Filtering exhibit functions

Updating some function filters in Omeka/ExhibitBuilder 2.0. The following seems to work except for the fact the the exhibit pages now always return a thumbnail image instead of letting the page template decide between thumbnails and fullsize. Why?

add_filter('exhibit_builder_attachment_markup','my_exhibit_builder_attachment_markup');
function my_exhibit_builder_attachment_markup($attachment, $fileOptions=array(), $linkProperties=array()){
    $attachment=exhibit_builder_page_attachment();
    if (!$attachment) {
        return '';
    }

    $item = $attachment['item'];
    $file = $attachment['file'];

    if (!isset($fileOptions['linkAttributes']['href'])) {
        $fileOptions['linkAttributes']['href'] = exhibit_builder_exhibit_item_uri($item);
    }

    if (!isset($fileOptions['imgAttributes']['alt'])) {
        $fileOptions['imgAttributes']['alt'] = metadata($item, array('Dublin Core', 'Title'));
    }

    if (!isset($fileOptions['imgAttributes']['rel'])) {
        $fileOptions['imgAttributes']['rel'] = 'tooltip';
    }

    if ($file) {
        $html = file_markup($file, $fileOptions, null);
    } else if($item) {
        $html = exhibit_builder_link_to_exhibit_item(null, $linkProperties, $item);
    }

    $html .= exhibit_builder_attachment_caption($attachment);

    return $html;
}

What am I missing this time?

Thanks -- E

Filters in Omeka 2.0 always take two parameters, never more.

The first parameter is the data to be filtered: that'd be the original HTML in this case, and the second parameter is an array of named "arguments" or "options."

The "exhibit_builder_attachment_markup" filter provides three arguments in that array: attachment, fileOptions, and linkProperties. You need to get these out of the arguments array to use them in your function. The practical upshot is that your filter function won't have the same signature as the original function.

Your signature should look like:

function my_filter($html, $args)

To get the arguments out of the $args array, you can use the PHP extract function, or you can explicitly get at each argument by its key:

$attachment = $args['attachment'];
$fileOptions = $args['fileOptions'];
$linkProperties = $args['linkProperties'];

Having that at the top of your function, combined with the changed signature, should get you back on track. The line you currently have assigning $attachment by calling exhibit_builder_page_attachment shouldn't be needed anymore.

Ok, that makes sense and works perfectly.

On the other hand, exhibit_builder_thumbnail_gallery($html,$args) seems to behave differently.

This doesn't work to set the options:

$args=array(
	'start' => $start,
	'end' => $end,
	'props' => $props,
	'thumbnail_type' => $thumbnailType
);

Nor does this:

$start = $args['start'];
$end = $args['end'];
$props = $args['props'];
$thumbnail_type = $args['thumbnail_type'];

And the options aren't compacted in the original function so maybe that's why extract($args) won't work either.

So I've just been doing it like this, which is presumably the wrong way to do it, though it does work as expected:

add_filter('exhibit_builder_thumbnail_gallery','my_exhibit_builder_thumbnail_gallery');
function my_exhibit_builder_thumbnail_gallery($start, $end, $props = array(), $thumbnailType = 'square_thumbnail'){
	$html = '';
	for ($i = 0; $i <= 12; $i++) {

	    if ($attachment = exhibit_builder_page_attachment($i)) {
	        $html .= "\n" . '<div class="exhibit-item">';
	        if ($attachment['file']) {
	        	$title=metadata($attachment['item'], array('Dublin Core', 'Title'));
	            $thumbnail = file_image($thumbnailType, array('rel'=>'tooltip','title'=>$title, 'alt'=>$title), $attachment['file']);
	            $html .= exhibit_builder_link_to_exhibit_item($thumbnail, array(), $attachment['item']);
	        }
	        $html .= exhibit_builder_attachment_caption($attachment);
	        $html .= '</div>' . "\n";
	    }
	}
	return $html;
}

Is the exhibit_builder_thumbnail_gallery() function going to be updated in the future or is it different for some other reason I'm not picking up on?

Thanks!

I think the only difference here from the guidelines above is a difference in capitalization on the $thumbnailType argument.

function my_exhibit_builder_thumbnail_gallery($html, $args) {
    $start = $args['start'];
    $end = $args['end'];
    $props = $args['props'];
    $thumbnailType = $args['thumbnail_type'];

    //...
}

Ah, of course. Thanks!