From e9f9aad49c78c92c11e46b93289b7c3b44cb6069 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 29 Apr 2022 19:08:15 +0000 Subject: [PATCH 1/7] Set IIIF Manifest title based on content title. --- .../src/Plugin/views/style/IIIFManifest.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php index 073ca04e..779451c2 100644 --- a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php +++ b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php @@ -121,18 +121,22 @@ class IIIFManifest extends StylePluginBase { $iiif_address = $this->iiifConfig->get('iiif_server'); if (!is_null($iiif_address) && !empty($iiif_address)) { // Get the current URL being requested. - $request_url = $this->request->getSchemeAndHttpHost() . $this->request->getRequestUri(); + $request_host = $this->request->getSchemeAndHttpHost(); + $request_url = $this->request->getRequestUri(); // Strip off the last URI component to get the base ID of the URL. // @todo assumming the view is a path like /node/1/manifest.json $url_components = explode('/', $request_url); array_pop($url_components); - $iiif_base_id = implode('/', $url_components); + $content_path = implode('/', $url_components); + $iiif_base_id = $request_host . '/' . $content_path; + + // @see https://iiif.io/api/presentation/2.1/#manifest $json += [ '@type' => 'sc:Manifest', '@id' => $request_url, // If the View has a title, set the View title as the manifest label. - 'label' => $this->view->getTitle() ?: 'IIIF Manifest', + 'label' => $this->view->getTitle() ?: $this->getEntityTitle($content_path), '@context' => 'http://iiif.io/api/presentation/2/context.json', // @see https://iiif.io/api/presentation/2.1/#sequence 'sequences' => [ @@ -260,6 +264,25 @@ class IIIFManifest extends StylePluginBase { return $canvases; } + /** + * Pull a title from the node or media passed to this view. + * + * @param string $content_path + * @return string + */ + public function getEntityTitle(string $content_path): string { + $entity_title = $this->t('IIIF Manifest'); + $params = \Drupal\Core\Url::fromUserInput($content_path)->getRouteParameters(); + if (isset($params['node'])) { + $node = \Drupal\node\Entity\Node::load($params['node']); + $entity_title = $node->getTitle(); + } elseif (isset($params['media'])) { + $media = \Drupal\media\Entity\Media::load($params['media']); + $entity_title = $media->getName(); + } + return $entity_title; + } + /** * {@inheritdoc} */ From 71b1cb5d645e2303390f42f1c1b6cc85506f1aa1 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 2 May 2022 14:25:22 +0000 Subject: [PATCH 2/7] Add try() wrapper to IIIF manifest title generate function. --- .../src/Plugin/views/style/IIIFManifest.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php index 779451c2..2dfe5011 100644 --- a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php +++ b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php @@ -130,7 +130,6 @@ class IIIFManifest extends StylePluginBase { $content_path = implode('/', $url_components); $iiif_base_id = $request_host . '/' . $content_path; - // @see https://iiif.io/api/presentation/2.1/#manifest $json += [ '@type' => 'sc:Manifest', @@ -272,13 +271,17 @@ class IIIFManifest extends StylePluginBase { */ public function getEntityTitle(string $content_path): string { $entity_title = $this->t('IIIF Manifest'); - $params = \Drupal\Core\Url::fromUserInput($content_path)->getRouteParameters(); - if (isset($params['node'])) { - $node = \Drupal\node\Entity\Node::load($params['node']); - $entity_title = $node->getTitle(); - } elseif (isset($params['media'])) { - $media = \Drupal\media\Entity\Media::load($params['media']); - $entity_title = $media->getName(); + try { + $params = \Drupal\Core\Url::fromUserInput($content_path)->getRouteParameters(); + if (isset($params['node'])) { + $node = \Drupal\node\Entity\Node::load($params['node']); + $entity_title = $node->getTitle(); + } elseif (isset($params['media'])) { + $media = \Drupal\media\Entity\Media::load($params['media']); + $entity_title = $media->getName(); + } + } catch (\InvalidArgumentException $e) { + } return $entity_title; } From 92d5a7fbbde578b6ea37b27b819cddd521b998a4 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Thu, 5 May 2022 19:14:54 +0000 Subject: [PATCH 3/7] Fix Coder errors in IIIF views style plugin. --- .../src/Plugin/views/style/IIIFManifest.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php index 2dfe5011..0ebc213e 100644 --- a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php +++ b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php @@ -5,6 +5,7 @@ namespace Drupal\islandora_iiif\Plugin\views\style; use Drupal\views\Plugin\views\style\StylePluginBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Core\Url; use Drupal\views\ResultRow; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -267,20 +268,25 @@ class IIIFManifest extends StylePluginBase { * Pull a title from the node or media passed to this view. * * @param string $content_path + * The path of the content being requested. + * * @return string + * The entity's title. */ public function getEntityTitle(string $content_path): string { $entity_title = $this->t('IIIF Manifest'); try { - $params = \Drupal\Core\Url::fromUserInput($content_path)->getRouteParameters(); + $params = Url::fromUserInput($content_path)->getRouteParameters(); if (isset($params['node'])) { - $node = \Drupal\node\Entity\Node::load($params['node']); + $node = \Drupal::entityTypeManager()->getStorage('node')->load($params['node']); $entity_title = $node->getTitle(); - } elseif (isset($params['media'])) { - $media = \Drupal\media\Entity\Media::load($params['media']); + } + elseif (isset($params['media'])) { + $media = \Drupal::entityTypeManager()->getStorage('media')->load($params['media']); $entity_title = $media->getName(); } - } catch (\InvalidArgumentException $e) { + } + catch (\InvalidArgumentException $e) { } return $entity_title; From 52d3df1462f7df95b20d51a9e8798b9f188509ee Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Thu, 12 May 2022 19:06:32 +0000 Subject: [PATCH 4/7] Suppress 'Schema incomplete' error in Functional test. --- .../src/Functional/IslandoraImageFormatterTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/src/Functional/IslandoraImageFormatterTest.php b/tests/src/Functional/IslandoraImageFormatterTest.php index 2793cf49..75003463 100644 --- a/tests/src/Functional/IslandoraImageFormatterTest.php +++ b/tests/src/Functional/IslandoraImageFormatterTest.php @@ -10,6 +10,11 @@ namespace Drupal\Tests\islandora\Functional; */ class IslandoraImageFormatterTest extends IslandoraFunctionalTestBase { + /** + * @var bool Suppresses "Schema incomplete" error. + */ + protected $strictConfigSchema = FALSE; + /** * @covers \Drupal\islandora\Plugin\Field\FieldFormatter\IslandoraImageFormatter::viewElements */ @@ -26,15 +31,16 @@ class IslandoraImageFormatterTest extends IslandoraFunctionalTestBase { // Create an image media type. $testImageMediaType = $this->createMediaType('image', ['id' => 'test_image_media_type']); $testImageMediaType->save(); - $this->createEntityReferenceField('media', $testImageMediaType->id(), 'field_media_of', 'Media Of', 'node', 'default', [], 2); - + $this->createEntityReferenceField('media', $testImageMediaType->id(), 'field_media_of', 'Media Of', 'node', 'default', [], 2);("Got past create media type."); // Set the display mode to use the islandora_image formatter. // Also, only show the image on display to remove clutter. $display_options = [ 'type' => 'islandora_image', - 'settings' => ['image_style' => NULL, 'image_link' => 'content'], + 'settings' => [/*'image_style' => NULL,*/ 'image_link' => 'content'], ]; + $display = $this->container->get('entity_display.repository')->getViewDisplay('media', $testImageMediaType->id(), 'default'); + $display->setComponent('field_media_image', $display_options) ->removeComponent('created') ->removeComponent('uid') @@ -47,7 +53,6 @@ class IslandoraImageFormatterTest extends IslandoraFunctionalTestBase { 'title' => 'Test Node', ]); $node->save(); - // Make a image for the Media. $file = $this->container->get('entity_type.manager')->getStorage('file')->create([ 'uid' => $account->id(), From 11bc7886ea13d6d5b674d8fb16ff7b17f09ee834 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 13 May 2022 19:20:40 +0000 Subject: [PATCH 5/7] Update islandora_image schema to fix failing test. --- config/schema/islandora.schema.yml | 8 ++++++++ .../Functional/IslandoraImageFormatterTest.php | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config/schema/islandora.schema.yml b/config/schema/islandora.schema.yml index de7a3e46..0ee69fc1 100644 --- a/config/schema/islandora.schema.yml +++ b/config/schema/islandora.schema.yml @@ -169,3 +169,11 @@ field.formatter.settings.islandora_image: image_style: type: string label: 'Image style' + image_loading: + type: mapping + label: 'Image loading settings' + mapping: + attribute: + type: string + label: 'Loading attribute' + diff --git a/tests/src/Functional/IslandoraImageFormatterTest.php b/tests/src/Functional/IslandoraImageFormatterTest.php index 75003463..33f6e1e6 100644 --- a/tests/src/Functional/IslandoraImageFormatterTest.php +++ b/tests/src/Functional/IslandoraImageFormatterTest.php @@ -10,11 +10,6 @@ namespace Drupal\Tests\islandora\Functional; */ class IslandoraImageFormatterTest extends IslandoraFunctionalTestBase { - /** - * @var bool Suppresses "Schema incomplete" error. - */ - protected $strictConfigSchema = FALSE; - /** * @covers \Drupal\islandora\Plugin\Field\FieldFormatter\IslandoraImageFormatter::viewElements */ @@ -31,16 +26,21 @@ class IslandoraImageFormatterTest extends IslandoraFunctionalTestBase { // Create an image media type. $testImageMediaType = $this->createMediaType('image', ['id' => 'test_image_media_type']); $testImageMediaType->save(); - $this->createEntityReferenceField('media', $testImageMediaType->id(), 'field_media_of', 'Media Of', 'node', 'default', [], 2);("Got past create media type."); + $this->createEntityReferenceField('media', $testImageMediaType->id(), 'field_media_of', 'Media Of', 'node', 'default', [], 2); // Set the display mode to use the islandora_image formatter. // Also, only show the image on display to remove clutter. $display_options = [ 'type' => 'islandora_image', - 'settings' => [/*'image_style' => NULL,*/ 'image_link' => 'content'], + 'settings' => [ + 'image_style' => '', + 'image_link' => 'content', + 'image_loading' => [ + 'attribute' => 'eager', + ], + ], ]; $display = $this->container->get('entity_display.repository')->getViewDisplay('media', $testImageMediaType->id(), 'default'); - $display->setComponent('field_media_image', $display_options) ->removeComponent('created') ->removeComponent('uid') From f6fa77984b08e78372a50984292fe0b49aa2fce8 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 16 May 2022 16:29:05 +0000 Subject: [PATCH 6/7] Islandora Image schema inherits from parent. --- config/schema/islandora.schema.yml | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/config/schema/islandora.schema.yml b/config/schema/islandora.schema.yml index 0ee69fc1..c98679eb 100644 --- a/config/schema/islandora.schema.yml +++ b/config/schema/islandora.schema.yml @@ -158,22 +158,6 @@ condition.plugin.node_had_namespace: pid_field: type: ignore label: 'PID field' - field.formatter.settings.islandora_image: - type: mapping - label: 'Image field display format settings' - mapping: - image_link: - type: string - label: 'Link image to' - image_style: - type: string - label: 'Image style' - image_loading: - type: mapping - label: 'Image loading settings' - mapping: - attribute: - type: string - label: 'Loading attribute' - + type: field.formatter.settings.image + label: 'Islandora image field display format settings' From e5a1f99c5710b051bb22f23a36d04b9110bf3787 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Thu, 19 May 2022 13:58:29 +0000 Subject: [PATCH 7/7] IIIF Manifest: Use dependency injection for EntityTypeManager service. --- .../src/Plugin/views/style/IIIFManifest.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php index 0ebc213e..13f83e7d 100644 --- a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php +++ b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php @@ -3,6 +3,7 @@ namespace Drupal\islandora_iiif\Plugin\views\style; use Drupal\views\Plugin\views\style\StylePluginBase; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Url; @@ -69,6 +70,13 @@ class IIIFManifest extends StylePluginBase { */ protected $iiifConfig; + /** + * The Drupal Entity Type Manager service. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + /** * The Drupal Filesystem. * @@ -86,12 +94,13 @@ class IIIFManifest extends StylePluginBase { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, FileSystemInterface $file_system, Client $http_client, MessengerInterface $messenger) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, EntityTypeManagerInterface $entity_type_manager, FileSystemInterface $file_system, Client $http_client, MessengerInterface $messenger) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->serializer = $serializer; $this->request = $request; $this->iiifConfig = $iiif_config; + $this->entityTypeManager = $entity_type_manager; $this->fileSystem = $file_system; $this->httpClient = $http_client; $this->messenger = $messenger; @@ -108,6 +117,7 @@ class IIIFManifest extends StylePluginBase { $container->get('serializer'), $container->get('request_stack')->getCurrentRequest(), $container->get('config.factory')->get('islandora_iiif.settings'), + $container->get('entity_type.manager'), $container->get('file_system'), $container->get('http_client'), $container->get('messenger') @@ -278,11 +288,11 @@ class IIIFManifest extends StylePluginBase { try { $params = Url::fromUserInput($content_path)->getRouteParameters(); if (isset($params['node'])) { - $node = \Drupal::entityTypeManager()->getStorage('node')->load($params['node']); + $node = $this->entityTypeManager->getStorage('node')->load($params['node']); $entity_title = $node->getTitle(); } elseif (isset($params['media'])) { - $media = \Drupal::entityTypeManager()->getStorage('media')->load($params['media']); + $media = $this->entityTypeManager->getStorage('media')->load($params['media']); $entity_title = $media->getName(); } }