Skip to content

Commit

Permalink
Fix phpcs and phpstan level 5 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
amym-li committed Jun 8, 2023
1 parent a5923e9 commit 4c458eb
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 27 deletions.
56 changes: 41 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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.
2 changes: 1 addition & 1 deletion css/mirador.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

.node .field--type-image {
float: none !important;
}
}
6 changes: 3 additions & 3 deletions islandora_mirador.install
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ function islandora_mirador_install() {
* Implements hook_update().
*/
function islandora_mirador_update_8001() {
//_get_or_create_tag();
// _get_or_create_tag();
}

/**
* Looks up or creates Mirador term.
*/
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',
Expand Down
4 changes: 2 additions & 2 deletions islandora_mirador.module
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
2 changes: 1 addition & 1 deletion src/Plugin/Block/MiradorBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
],
];
Expand Down
9 changes: 6 additions & 3 deletions src/Plugin/Field/FieldFormatter/MiradorImageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions templates/mirador.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,3 @@


{{ attach_library('islandora_mirador/viewer') }}


0 comments on commit 4c458eb

Please sign in to comment.