metadata() disrupts add_filter() [Omeka 2.0.2]

I'm trying to filter some metadata values in the public view. What I want is to append information to a metadata code. This code is a reference to an Identifier of another Item Type. Sometimes there are multiple codes for the item, so it has to repeat the function that appends information to this code.

I found out that whenever I call metadata in the last function (get_type_description()), the subsequent values are not filtered. It just doesn't execute subject_info() anymore and I can't figure out why. Am I doing something wrong? Do you have a solution for this?

What I did was (short version):

    class DataLinkerPlugin extends Omeka_Plugin_AbstractPlugin{
    protected $_hooks = array('public_head');

    public function hookPublicHead($args){
    add_filter(array('Display', 'Item', 'Dublin Core', 'Subject'), 'subject_info', 7);
    }
    }

    function subject_info($args){
    $type_information = get_type_description($args);
    $html = $args . " - " $type_information;
    return $html;
    }

    function get_type_description($search_string){
    $db = get_db();
    $sql = " SELECT items.id
    FROM {$db->Item} items
    JOIN {$db->ElementText} element_texts
    ON items.id = element_texts.record_id
    JOIN {$db->Element} elements
    ON element_texts.element_id = elements.id
    JOIN {$db->ElementSet} element_sets
    ON elements.element_set_id = element_sets.id
    WHERE element_sets.name = 'Dublin Core'
    AND elements.name = 'Identifier'
    AND element_texts.text = ?";
    _log("3 BEFORE FETCHING: ");
    $itemIds = $db->fetchAll($sql, $search_string);
    if (count($itemIds) > 0){
    $found_item = get_record_by_id('item', $itemIds[0]["id"]);
    $temp_return = metadata($found_item, array('Dublin Core', 'Title'));
    return $temp_return;
    }
    return "Type doesn't exist";
    }

Thanks!

Unless I'm missing something obvious, it looks like your filter is for Dublin Core Subject, and the metadata call is for Dublin Core Title.

Or are you saying that after you call metadata that time that later calls to metadata on the Subject don't get filtered?

Yes I want to return the title of an item to add to the metadata field.

It's kinda hard to explain, but what I'm saying that the filter always works perfectly on the first metadata value (first code that I want to supplement with a title) and the next one doesn't even seem to get filtered at all. It does however get filtered when I don't execute metadata() in the function get_type_description().

So what I want is:

Subject
AT 2000
AT 2001
AT 2004

to become:

Subject
AT 2000 - title 1
AT 2001 - title 2
AT 2004 - another title

but this happens:

Subject
AT 2000 - title 1
AT 2001
AT 2004

I can confirm this. The problem happens when you use metadata on a different record or metadata field in the middle of another metadata call (which happens when filtering and on items/show with multiples of one type of metadata).

I've just now pushed a fix, but I don't know when it will be released. As a workaround you could directly call getElementTexts on the item in your filter:

$temp_return = html_escape($found_item->getElementTexts('Dublin Core', 'Title')[0]['text']);