Problem with handleResourceTitle after updating to version 3.2.1

I’ve recently to version 3.2.1 and everything in my custom module works fine, except that when i link one property to an Omeka resource i don’t see the rendered title anymore, but the json of the resource:

In the past everything worked fine with this function:

/**
     * Manage the parsing of the title.
     *
     * @param Event $event
     */
    public function handleResourceTitle(Event $event): void
    {
        $resource = $event->getTarget();
        $template = $resource->resourceTemplate();
        
        if ($template && $property = $template->titleProperty()) {
            $title = $resource->value($property->term());
            $properties = json_decode($title, true);

            $event->setParam('title', (string) $title);
            if(isset($properties[0]['@type'])){
                $values = [];
                
                foreach ($properties[0] as $key => $val) {
                    if (is_array($val) || is_object($val)){
                        foreach ($val as $innerKey => $innerVal) {
                            if($innerVal['@value']){
                                $values[$key] = $innerVal['@value'];
                                continue;
                            }
                            if($innerVal['label']){
                                $values[$key] = $innerVal['label'];
                                continue;
                            }
                            foreach ($innerVal as $secondKey => $secondVal) {
                                $values[$key] = $secondVal['@value'];
                                if($secondVal['@value']){
                                    $values[$key] = $secondVal['@value'];
                                }
                                if($secondVal['label']){
                                    $values[$key] = $secondVal['label'];
                                }
                            }
                        }
                    }
                }
                $cleanedTitle = implode('; ', $values);
                $event->setParam('title', (string) $cleanedTitle);
            }
            else {
                $event->setParam('title', (string) $title);
            }
            
        }
    }

How can i fix this?

This is an upgrade from what prior version? I don’t think anything really changed in 3.2.1 specifically in dealing with titles but if you’re coming from a significantly older version then maybe.

What event is this attached to, it’s the rep.resource.title event I assume?

Yes, from the rep.resource.title event which i call here:

$sharedEventManager->attach(
            \Omeka\Api\Representation\ItemRepresentation::class,
            'rep.resource.title',
            [$this, 'handleResourceTitle']
        );
        $sharedEventManager->attach(
            \Omeka\Api\Representation\ItemSetRepresentation::class,
            'rep.resource.title',
            [$this, 'handleResourceTitle']
        );
        $sharedEventManager->attach(
            \Omeka\Api\Representation\MediaRepresentation::class,
            'rep.resource.title',
            [$this, 'handleResourceTitle']
        );
        $sharedEventManager->attach(
            \Annotate\Api\Representation\AnnotationRepresentation::class,
            'rep.resource.title',
            [$this, 'handleResourceTitle']
        );

Double-checking simple things: the module is still installed and active, right?

Does the event just not work at all? Like, if you set the title param to something static just for testing purposes?

Yes the module is installed.
Even if i replace the title with a fixed string it i have the same issue: the title remains the content of the @value.

In general, when i import an item as an omeka resource i see the correct title:

But as soon as i save it i see the content of the @value:

This improper display is the same on the public and private sides?

My best guess would be that where you’re seeing it incorrectly, the code isn’t actually asking for the “title”, possibly getting the dcterms:title directly instead. (I believe I’m remembering correctly that that’s how your setup here works, with the JSON directly in those values and then filtered for display).

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.