How to extract the value of a uri from $item->displayValues(); in a module

Problem: I’m creating a module and I’m trying to extract whatever the URI is that corresponds to an item’s title through code. So, in something like the item-with-metadata, you see code that just says “$item->displayValues():” but I want to get just the uri of the title, not anything else. I’ve found this code snippet from the file, Uri.php, which is ultimately what I need to use in my module, but of course it doesn’t work because I’m not including the correct files. For instance, I’ve tried including what is at the top of Uri.php, such as “use Omeka\Api\Adapter\AbstractEntityAdapter;
use Omeka\Api\Representation\ValueRepresentation; etc”, but without success.

If someone could steer me in the right direction as to what I’m doing wrong to get this to work, I would greatly appreciate it as I’ve spent a lot of time already. Thanks!

public function render(PhpRenderer $view, ValueRepresentation $value)
{
$uri = $value->uri();
$uriLabel = $value->value();
if (!$uriLabel) {
$uriLabel = $uri;
}
return $view->hyperlink($uriLabel, $uri, [‘class’ => ‘uri-value-link’]);
}

If you have access to the item, you can get it’s uri directly: $item->url();. So what is the issue?

No, I’m not trying to get to the url of the item, I’m trying to find the uri of the item title (see screen shot). So right now, the thumbnail of the image is set to go to the item’s url, but I want to build a module that includes the ability to choose for the image to link to the uri, which is the url of the “view collection” link.
08%20AM

displayValues is just used to, as it says, display. It doesn’t give you any capability to retrieve individual values.

You want to use the value() method on $item instead. That will return you a ValueRepresentation object that you can call uri() on.

1 Like

Thank you, I will try that and see if I can get it to work.

So, I’m close … if I do the following:

$item->value(‘dcterms:title’, [‘type’ => ‘uri’]);

It retrieves the uri, but only the label and NOT the actual url of that value…so it returns “View collection…”. I want it to return “https://muse.union.edu/arl-collections?_ga=2.86429085.462434040.1534166823-1143246503.1532965644”.

Do you happen to know how I can get that url of the uri type?

Thanks

Did you try calling ->uri() on the object you get back from value()?

Ahhhh ok! Now I tried the following, and it works!

$specialLink = $item->value(‘dcterms:title’, [‘type’ => ‘uri’]);

echo $specialLink->uri();

Thanks!!