Browse Source

Add try() wrapper to IIIF manifest title generate function.

pull/869/head
Alexander O'Neill 3 years ago
parent
commit
71b1cb5d64
  1. 19
      modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php

19
modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php

@ -130,7 +130,6 @@ class IIIFManifest extends StylePluginBase {
$content_path = implode('/', $url_components); $content_path = implode('/', $url_components);
$iiif_base_id = $request_host . '/' . $content_path; $iiif_base_id = $request_host . '/' . $content_path;
// @see https://iiif.io/api/presentation/2.1/#manifest // @see https://iiif.io/api/presentation/2.1/#manifest
$json += [ $json += [
'@type' => 'sc:Manifest', '@type' => 'sc:Manifest',
@ -272,13 +271,17 @@ class IIIFManifest extends StylePluginBase {
*/ */
public function getEntityTitle(string $content_path): string { public function getEntityTitle(string $content_path): string {
$entity_title = $this->t('IIIF Manifest'); $entity_title = $this->t('IIIF Manifest');
$params = \Drupal\Core\Url::fromUserInput($content_path)->getRouteParameters(); try {
if (isset($params['node'])) { $params = \Drupal\Core\Url::fromUserInput($content_path)->getRouteParameters();
$node = \Drupal\node\Entity\Node::load($params['node']); if (isset($params['node'])) {
$entity_title = $node->getTitle(); $node = \Drupal\node\Entity\Node::load($params['node']);
} elseif (isset($params['media'])) { $entity_title = $node->getTitle();
$media = \Drupal\media\Entity\Media::load($params['media']); } elseif (isset($params['media'])) {
$entity_title = $media->getName(); $media = \Drupal\media\Entity\Media::load($params['media']);
$entity_title = $media->getName();
}
} catch (\InvalidArgumentException $e) {
} }
return $entity_title; return $entity_title;
} }

Loading…
Cancel
Save