From 4c458ebeb154559aca5648ad0104cec09483783e Mon Sep 17 00:00:00 2001 From: Amy Li Date: Thu, 8 Jun 2023 15:01:26 -0400 Subject: [PATCH] Fix phpcs and phpstan level 5 errors --- README.md | 56 ++++++++++++++----- css/mirador.css | 2 +- islandora_mirador.install | 6 +- islandora_mirador.module | 4 +- src/Plugin/Block/MiradorBlock.php | 2 +- .../FieldFormatter/MiradorImageFormatter.php | 9 ++- templates/mirador.html.twig | 2 - 7 files changed, 54 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 397ae4c..ab8e930 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ## Introduction -A Drupal 9 field formatter and block that can display an image or paged content using an IIIF image server and the Mirador viewer. +A Drupal 9 field formatter and block that can display an image or paged content +using an IIIF image server and the Mirador viewer. More information on the Mirador viewer can be found on the [Project Mirador](https://projectmirador.org/) page. @@ -12,34 +13,59 @@ More information on the Mirador viewer can be found on the [Project Mirador](htt As a Drupal module, this module can be installed using Composer, Drush, or file upload. More in depth instructions can be found on [Drupal's docs](https://www.drupal.org/docs/extending-drupal/installing-modules). ## Configuration -Remember to first set up the configuration for the Islandora IIIF module and the IIIF image server. +Remember to first set up the configuration for the Islandora IIIF module and +the IIIF image server. -This module's configuration can be found under Configuration > Media > Mirador Settings (`admin/config/media/mirador`). This is where the IIIF Manifest URL for single media should be configured, and this should link to the path of the Media IIIF Manifest view. Configuration of the IIIF Manifest URL for content with multiple pages is done separately when placing a block. +This module's configuration can be found under Configuration > Media > +Mirador Settings (`admin/config/media/mirador`). This is where the IIIF +Manifest URL for single media should be configured, and this should link +to the path of the Media IIIF Manifest view. Configuration of the IIIF Manifest +URL for content with multiple pages is done separately when placing a block. ## Usage ### Field Formatter (single images) -The field formatter can be used to display content with a single image. This works on content that contains a field with an entity reference to a media item of the image type. +The field formatter can be used to display content with a single image. This +works on content that contains a field with an entity reference to a media +item of the image type. -To use the field formatter, change the display format to Mirador under Structure > Media types > Image > Edit > Manage display (`admin/structure/media/manage/image/display`). +To use the field formatter, change the display format to Mirador under +Structure > Media types > Image > Edit > Manage display +(`admin/structure/media/manage/image/display`). ### Block (paged content) -The block can be used to display paged content. This can work with a couple different node structures, but all require the manual set-up of a IIIF Manifest view. +The block can be used to display paged content. This can work with a couple +different node structures, but all require the manual set-up of a IIIF Manifest +view. #### Setting up a IIIF Manifest view -To create a new IIIF Manifest view go to Structure > Views > Add view (`admin/structure/views/add`), check "Provide a REST export", and provide a path (such as `node/%node/book-manifest`). +To create a new IIIF Manifest view go to Structure > Views > Add view +(`admin/structure/views/add`), check "Provide a REST export", and provide +a path (such as `node/%node/book-manifest`). -1. Under Advanced > Relationships, add a relationship to the field used for images. +1. Under Advanced > Relationships, add a relationship to the field used for +images. 2. Under Format, change the Show from "Entity" to "Fields". -3. Add a field "Image" from category "Media", and ensure that the relationship is the one set up in the earlier step. -4. Under Format, change the Format from "Serializer" to "IIIF Manifest", and make sure the Media is selected under Tile source field(s). -5. Under Advanced > Contextual Filters, add a contextual filter based on the structure of your content. +3. Add a field "Image" from category "Media", and ensure that the relationship +is the one set up in the earlier step. +4. Under Format, change the Format from "Serializer" to "IIIF Manifest", and +make sure the Media is selected under Tile source field(s). +5. Under Advanced > Contextual Filters, add a contextual filter based on the +structure of your content. -Below are some examples of content structures and ways to set up the contextual filter for the manifest view: +Below are some examples of content structures and ways to set up the contextual +filter for the manifest view: -- Recommended: For a content type where each node only has 1 image and each node has a field that specifies if the node is a "part of" another node, the contextual filter can be set as the name of that field "part of". -- For a content type where each node can have more than 1 image, the filter can be set as the content ID. +- Recommended: For a content type where each node only has 1 image and each +node has a field that specifies if the node is a "part of" another node, the +contextual filter can be set as the name of that field "part of". +- For a content type where each node can have more than 1 image, the filter +can be set as the content ID. The filter and sorting criteria in the view can be modified as wanted. #### Placing the block -Once the manifest is set up, the block can be placed by going to Structure > Block layout (`admin/structure/block`) and placing the Mirador block under Content. When prompted for a IIIF Manifest URL, enter the URL to the manifest created earlier. The block's visibility can be set, just like any other Drupal block. +Once the manifest is set up, the block can be placed by going to Structure > +Block layout (`admin/structure/block`) and placing the Mirador block under +Content. When prompted for a IIIF Manifest URL, enter the URL to the manifest +created earlier. The block's visibility can be set, just like any other Drupal +block. diff --git a/css/mirador.css b/css/mirador.css index ba7ddad..6fdbb7f 100644 --- a/css/mirador.css +++ b/css/mirador.css @@ -4,4 +4,4 @@ .node .field--type-image { float: none !important; -} \ No newline at end of file +} diff --git a/islandora_mirador.install b/islandora_mirador.install index d27ddc7..10b1f7e 100644 --- a/islandora_mirador.install +++ b/islandora_mirador.install @@ -18,7 +18,7 @@ function islandora_mirador_install() { * Implements hook_update(). */ function islandora_mirador_update_8001() { - //_get_or_create_tag(); + // _get_or_create_tag(); } /** @@ -26,9 +26,9 @@ function islandora_mirador_update_8001() { */ function _get_or_create_tag() { $term_name = 'Mirador'; - $test_terms = taxonomy_term_load_multiple_by_name($term_name); + $test_terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => $term_name]); if (!$test_terms) { - $term = Term::create([ + Term::create([ 'parent' => [], 'name' => $term_name, 'vid' => 'islandora_display', diff --git a/islandora_mirador.module b/islandora_mirador.module index 6efce6e..91a0184 100644 --- a/islandora_mirador.module +++ b/islandora_mirador.module @@ -29,9 +29,9 @@ function template_preprocess_mirador(&$variables) { $variables['mirador_view_id'] = Html::getUniqueId($variables['mirador_view_id']); $variables['#attached']['drupalSettings']['mirador_view_id'] = $variables['mirador_view_id']; - // for dsu-utsc + // For dsu-utsc. if (!empty(\Drupal::hasService('jwt.authentication.jwt'))) { $variables['#attached']['drupalSettings']['token'] = \Drupal::service('jwt.authentication.jwt')->generateToken(); } - + } diff --git a/src/Plugin/Block/MiradorBlock.php b/src/Plugin/Block/MiradorBlock.php index 294eb32..c8bea59 100644 --- a/src/Plugin/Block/MiradorBlock.php +++ b/src/Plugin/Block/MiradorBlock.php @@ -119,7 +119,7 @@ public function build() { 'drupalSettings' => [ 'iiif_manifest_url' => $manifest_url, 'mirador_view_id' => $id, - 'default_thumbnail' => "far-bottom" + 'default_thumbnail' => "far-bottom", ], ], ]; diff --git a/src/Plugin/Field/FieldFormatter/MiradorImageFormatter.php b/src/Plugin/Field/FieldFormatter/MiradorImageFormatter.php index 32b1bef..dc8a895 100644 --- a/src/Plugin/Field/FieldFormatter/MiradorImageFormatter.php +++ b/src/Plugin/Field/FieldFormatter/MiradorImageFormatter.php @@ -10,6 +10,7 @@ use Drupal\Core\Utility\Token; use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Field\EntityReferenceFieldItemListInterface; /** * Mirador FieldFormatter plugin. @@ -73,7 +74,7 @@ class MiradorImageFormatter extends ImageFormatterBase implements ContainerFacto * The route match. */ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, ConfigFactoryInterface $config_factory, Token $token, RouteMatchInterface $route_match) { - parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $config_factory); + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); $this->token = $token; $this->routeMatch = $route_match; $this->configFactory = $config_factory; @@ -103,7 +104,9 @@ public static function create(ContainerInterface $container, array $configuratio public function viewElements(FieldItemListInterface $items, $langcode) { $elements = []; $settings = $this->getSettings(); - $files = $this->getEntitiesToView($items, $langcode); + if ($items instanceof EntityReferenceFieldItemListInterface) { + $files = $this->getEntitiesToView($items, $langcode); + } if (empty($files)) { return $elements; } @@ -120,7 +123,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { 'drupalSettings' => [ 'iiif_manifest_url' => $manifest_url, 'mirador_view_id' => $id, - 'default_thumbnail' => false + 'default_thumbnail' => FALSE, ], ], '#settings' => $settings, diff --git a/templates/mirador.html.twig b/templates/mirador.html.twig index c30fb4d..6dbe0c1 100644 --- a/templates/mirador.html.twig +++ b/templates/mirador.html.twig @@ -59,5 +59,3 @@ {{ attach_library('islandora_mirador/viewer') }} - -