Exhibit Builder - cover image to show instead of random item image from exhibit?

I am trying to figure out how to change the following bit from a function to show the exhibit “cover” image instead of a random image from an item in the exhibit:

if ($recentExhibit) {
foreach( $recentExhibit as $index => $exhibit){
   $html .= '<h3>' . exhibit_builder_link_to_exhibit($recentExhibit[$index]) . '</h3>';
   
   if ($item = get_record('Item', array('sort_field' => 'random', 'exhibit' => $recentExhibit[$index]->id, 'hasImage' => true))) {
        $html .= exhibit_builder_link_to_exhibit($recentExhibit[$index],
            item_image('square_thumbnail', array(), 0, $item),
            array('class' => 'image')
        );
   }

I know that this from the summary.php will do it, but I cant quite figure out how to adapt it

?php if ($exhibitImage = record_image($exhibit, ‘square_thumbnail’)): ?>
<?php echo exhibit_builder_link_to_exhibit($exhibit, $exhibitImage, array('class' => 'image')); ?>
<?php endif; ?>

Would love any help, thank you!

Does it need to be adapted at all? It looks like it would work fine just dropped in as a replacement for the if ($item ...) block.

I dont know, I was trying to figure out what to replace - are you saying to replace $item with $block? - when I try that it gives me the same. I am thinking record_image is maybe the key to getting the “cover” image but I tried putting that in in place of get_record and that did not work…

I mean like this:

if ($recentExhibit) {
foreach( $recentExhibit as $index => $exhibit){
   $html .= '<h3>' . exhibit_builder_link_to_exhibit($exhibit) . '</h3>';
   
   if ($exhibitImage = record_image($exhibit, 'square_thumbnail')) {
        $html .= exhibit_builder_link_to_exhibit($exhibit, $exhibitImage, array('class' => 'image'));
   }

I was wrong in that there’s a small adaptation that had to be made here: the echo is replaced by the original function’s $html .=.

That works perfectly, thank you so much!