From 9b7b5d04cd0528c320bc6b9b2f79265a09327374 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Fri, 1 Sep 2023 09:58:15 -0300 Subject: [PATCH 1/8] Add normalizers. --- README.md | 50 +++++++- iiif_presentation_api.info.yml | 7 ++ iiif_presentation_api.services.yml | 18 +++ src/Encoder/V3/IiifP.php | 19 +++ src/IiifPresentationApiServiceProvider.php | 19 +++ src/Normalizer/V3/ContentEntityNormalizer.php | 112 ++++++++++++++++++ src/Normalizer/V3/FieldItemListNormalizer.php | 34 ++++++ src/Normalizer/V3/FieldItemNormalizer.php | 34 ++++++ src/Normalizer/V3/NormalizerBase.php | 80 +++++++++++++ 9 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 iiif_presentation_api.info.yml create mode 100644 iiif_presentation_api.services.yml create mode 100644 src/Encoder/V3/IiifP.php create mode 100644 src/IiifPresentationApiServiceProvider.php create mode 100644 src/Normalizer/V3/ContentEntityNormalizer.php create mode 100644 src/Normalizer/V3/FieldItemListNormalizer.php create mode 100644 src/Normalizer/V3/FieldItemNormalizer.php create mode 100644 src/Normalizer/V3/NormalizerBase.php diff --git a/README.md b/README.md index 3ab7ca0..278f23a 100644 --- a/README.md +++ b/README.md @@ -1 +1,49 @@ -# iiif_presentation_api \ No newline at end of file +# IIIF Presentation API + +## Introduction + +Provides serialization to IIIF Presentation API. + +## Requirements + +This module requires the following modules/libraries: + +* Serialization (part of Drupal core) + +## Installation + +Install as usual, see +[this](https://www.drupal.org/docs/extending-drupal/installing-modules) for +further information. + +## Configuration + +Out of the box the module provides minimal implementation and expects other +modules to either decorate or provide their own implementation by extending the +provided normalizers. + +For any content entity that should be exposed the format will need to be +configured as [documented by Drupal][1]. + +## Troubleshooting/Issues + +Having problems or solved one? contact +[discoverygarden](http://support.discoverygarden.ca). + +## Maintainers/Sponsors + +Current maintainers: + +* [discoverygarden](http://www.discoverygarden.ca) + +## Development + +If you would like to contribute to this module create an issue, pull request +and or contact +[discoverygarden](http://support.discoverygarden.ca). + +## License + +[GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt) + +[1]: https://www.drupal.org/docs/drupal-apis/restful-web-services-api/restful-web-services-api-overview#s-api-features] diff --git a/iiif_presentation_api.info.yml b/iiif_presentation_api.info.yml new file mode 100644 index 0000000..e8cd4df --- /dev/null +++ b/iiif_presentation_api.info.yml @@ -0,0 +1,7 @@ +name: IIIF Presentation API +type: module +description: 'Provides a IIIF Presentation API implementation for Drupal entities.' +package: DGI +core_version_requirement: ^9 || ^10 +dependencies: + - drupal:serialization diff --git a/iiif_presentation_api.services.yml b/iiif_presentation_api.services.yml new file mode 100644 index 0000000..05b3c1e --- /dev/null +++ b/iiif_presentation_api.services.yml @@ -0,0 +1,18 @@ +services: + serializer.encoder.iiif_presentation_api.iiif_p_v3.encoder: + class: 'Drupal\iiif_presentation_api\Encoder\V3\IiifP' + tags: + - { name: encoder, priority: 20, format: 'iiif-p-v3' } + serializer.normalizer.iiif_presentation_api.iiif_p_v3.content_entity: + class: 'Drupal\iiif_presentation_api\Normalizer\V3\ContentEntityNormalizer' + tags: + - { name: normalizer, priority: 10 } + arguments: ['@current_user'] + serializer.normalizer.iiif_presentation_api.iiif_p_v3.field_item_list: + class: 'Drupal\iiif_presentation_api\Normalizer\V3\FieldItemListNormalizer' + tags: + - { name: normalizer, priority: 10 } + serializer.normalizer.iiif_presentation_api.iiif_p_v3.field_item: + class: 'Drupal\iiif_presentation_api\Normalizer\V3\FieldItemNormalizer' + tags: + - { name: normalizer, priority: 10 } diff --git a/src/Encoder/V3/IiifP.php b/src/Encoder/V3/IiifP.php new file mode 100644 index 0000000..c80a586 --- /dev/null +++ b/src/Encoder/V3/IiifP.php @@ -0,0 +1,19 @@ +has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), '\Drupal\Core\StackMiddleware\NegotiationMiddleware', TRUE)) { + $container->getDefinition('http_middleware.negotiation')->addMethodCall('registerFormat', ['iiif-p-v3', ['application/json']]); + } + } + +} diff --git a/src/Normalizer/V3/ContentEntityNormalizer.php b/src/Normalizer/V3/ContentEntityNormalizer.php new file mode 100644 index 0000000..0718788 --- /dev/null +++ b/src/Normalizer/V3/ContentEntityNormalizer.php @@ -0,0 +1,112 @@ +user = $user; + } + + /** + * {@inheritDoc} + */ + public function normalize($object, $format = NULL, array $context = []) { + + $normalized = []; + if (empty($context)) { + $context['base-depth'] = TRUE; + $normalized['@context'] = 'http://iiif.io/api/presentation/3/context.json'; + } + else { + $context['base-depth'] = FALSE; + } + $normalized += [ + 'id' => $this->getEntityUri($object, $context), + 'type' => $context['base-depth'] ? 'Manifest' : 'Canvas', + 'label' => [ + $object->language()->getId() => [$object->label()], + ], + ]; + + $context += [ + 'account' => $this->user, + ]; + + if (isset($context[static::SERIALIZATION_CONTEXT_CACHEABILITY])) { + $context[static::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheContexts(['user.roles']); + } + + $context['parent'] = [ + 'type' => $normalized['type'], + 'id' => $normalized['id'], + ]; + return $this->normalizeEntityFields($object, $format, $context, $normalized); + } + + /** + * Normalizes all fields present on a content entity. + * + * @param \Drupal\Core\Entity\ContentEntityInterface $object + * The entity being normalized. + * @param string $format + * The format being serialized. + * @param array $context + * An array containing any context being passed to the normalizers. + * @param array $normalized + * An array representing the normalized entity to be rendered. + * + * @return array + * The normalized representation of the entity. + */ + protected function normalizeEntityFields(ContentEntityInterface $object, string $format, array $context, array $normalized) { + $this->addCacheableDependency($context, $object); + foreach ($object->getFields() as $field) { + $access = $field->access('view', $context['account'], TRUE); + $this->addCacheableDependency($context, $access); + if (!$access->isAllowed()) { + continue; + } + $normalized_property = $this->serializer->normalize($field, $format, $context); + if (!empty($normalized_property)) { + $normalized = NestedArray::mergeDeep($normalized, (array) $normalized_property); + } + } + return $normalized; + } + + /** + * {@inheritDoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + ContentEntityInterface::class => TRUE, + ]; + } + +} diff --git a/src/Normalizer/V3/FieldItemListNormalizer.php b/src/Normalizer/V3/FieldItemListNormalizer.php new file mode 100644 index 0000000..e03a11c --- /dev/null +++ b/src/Normalizer/V3/FieldItemListNormalizer.php @@ -0,0 +1,34 @@ + TRUE, + ]; + } + +} diff --git a/src/Normalizer/V3/FieldItemNormalizer.php b/src/Normalizer/V3/FieldItemNormalizer.php new file mode 100644 index 0000000..6cfec9b --- /dev/null +++ b/src/Normalizer/V3/FieldItemNormalizer.php @@ -0,0 +1,34 @@ + FALSE, + ]; + } + +} diff --git a/src/Normalizer/V3/NormalizerBase.php b/src/Normalizer/V3/NormalizerBase.php new file mode 100644 index 0000000..308481e --- /dev/null +++ b/src/Normalizer/V3/NormalizerBase.php @@ -0,0 +1,80 @@ +format; + } + + /** + * Constructs the entity URI. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity. + * @param array $context + * Normalization/serialization context. + * + * @return string + * The entity URI. + */ + protected function getEntityUri(EntityInterface $entity, array $context = []) { + // Some entity types don't provide a canonical link template. + if ($entity->isNew()) { + return ''; + } + + $route_name = 'rest.entity.' . $entity->getEntityTypeId() . '.GET'; + if ($entity->hasLinkTemplate('canonical')) { + $url = $entity->toUrl('canonical'); + } + elseif (\Drupal::service('router.route_provider')->getRoutesByNames([$route_name])) { + $url = Url::fromRoute('rest.entity.' . $entity->getEntityTypeId() . '.GET', [$entity->getEntityTypeId() => $entity->id()]); + } + else { + return ''; + } + + $url->setAbsolute(); + if (!$url->isExternal()) { + $url->setRouteParameter('_format', 'iiif-p-v3'); + } + $generated_url = $url->toString(TRUE); + $this->addCacheableDependency($context, $generated_url); + return $generated_url->getGeneratedUrl(); + } + + /** + * {@inheritdoc} + */ + public function hasCacheableSupportsMethod(): bool { + return TRUE; + } + +} From bf92e90435b7257ed018c350d0d271765905f902 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Wed, 6 Sep 2023 11:34:48 -0300 Subject: [PATCH 2/8] Move the no-op to the base. --- src/Normalizer/V3/FieldItemListNormalizer.php | 8 -------- src/Normalizer/V3/FieldItemNormalizer.php | 8 -------- src/Normalizer/V3/NormalizerBase.php | 8 ++++++++ 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/Normalizer/V3/FieldItemListNormalizer.php b/src/Normalizer/V3/FieldItemListNormalizer.php index e03a11c..7b8bf82 100644 --- a/src/Normalizer/V3/FieldItemListNormalizer.php +++ b/src/Normalizer/V3/FieldItemListNormalizer.php @@ -14,14 +14,6 @@ class FieldItemListNormalizer extends NormalizerBase { */ protected $supportedInterfaceOrClass = FieldItemListInterface::class; - /** - * {@inheritDoc} - */ - public function normalize($object, $format = NULL, array $context = []) { - // XXX: No-op as other implementers can define what fields to normalize - // with a higher priority. - } - /** * {@inheritDoc} */ diff --git a/src/Normalizer/V3/FieldItemNormalizer.php b/src/Normalizer/V3/FieldItemNormalizer.php index 6cfec9b..78b5074 100644 --- a/src/Normalizer/V3/FieldItemNormalizer.php +++ b/src/Normalizer/V3/FieldItemNormalizer.php @@ -14,14 +14,6 @@ class FieldItemNormalizer extends NormalizerBase { */ protected $supportedInterfaceOrClass = FieldItemInterface::class; - /** - * {@inheritDoc} - */ - public function normalize($object, $format = NULL, array $context = []) { - // XXX: No-op as other implementers can define what fields to normalize - // with a higher priority. - } - /** * {@inheritDoc} */ diff --git a/src/Normalizer/V3/NormalizerBase.php b/src/Normalizer/V3/NormalizerBase.php index 308481e..51bceff 100644 --- a/src/Normalizer/V3/NormalizerBase.php +++ b/src/Normalizer/V3/NormalizerBase.php @@ -16,6 +16,14 @@ abstract class NormalizerBase extends SerializationNormalizerBase { */ protected $format = 'iiif-p-v3'; + /** + * {@inheritDoc} + */ + public function normalize($object, $format = NULL, array $context = []) { + // XXX: No-op fallback. We expect other implementers to define normalizers + // with a higher priority. + } + /** * {@inheritDoc} */ From 9350c4fe44321dd97e1dfdd681d7ae5bca805749 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 14 Sep 2023 14:34:07 -0300 Subject: [PATCH 3/8] Trait for URI generation + reworks. --- iiif_presentation_api.services.yml | 2 +- src/Normalizer/EntityUriTrait.php | 53 +++++++++++++++++++ src/Normalizer/RouterProviderTrait.php | 41 ++++++++++++++ src/Normalizer/V3/ContentEntityNormalizer.php | 15 ++++-- src/Normalizer/V3/NormalizerBase.php | 39 -------------- 5 files changed, 106 insertions(+), 44 deletions(-) create mode 100644 src/Normalizer/EntityUriTrait.php create mode 100644 src/Normalizer/RouterProviderTrait.php diff --git a/iiif_presentation_api.services.yml b/iiif_presentation_api.services.yml index 05b3c1e..51bcd3e 100644 --- a/iiif_presentation_api.services.yml +++ b/iiif_presentation_api.services.yml @@ -7,7 +7,7 @@ services: class: 'Drupal\iiif_presentation_api\Normalizer\V3\ContentEntityNormalizer' tags: - { name: normalizer, priority: 10 } - arguments: ['@current_user'] + arguments: ['@current_user', '@router.route_provider'] serializer.normalizer.iiif_presentation_api.iiif_p_v3.field_item_list: class: 'Drupal\iiif_presentation_api\Normalizer\V3\FieldItemListNormalizer' tags: diff --git a/src/Normalizer/EntityUriTrait.php b/src/Normalizer/EntityUriTrait.php new file mode 100644 index 0000000..f3b3930 --- /dev/null +++ b/src/Normalizer/EntityUriTrait.php @@ -0,0 +1,53 @@ +isNew()) { + return ''; + } + + $route_name = 'rest.entity.' . $entity->getEntityTypeId() . '.GET'; + if ($entity->hasLinkTemplate('canonical')) { + $url = $entity->toUrl('canonical'); + } + elseif ($this->getRouteProvider()->getRoutesByNames([$route_name])) { + $url = Url::fromRoute('rest.entity.' . $entity->getEntityTypeId() . '.GET', [$entity->getEntityTypeId() => $entity->id()]); + } + else { + return ''; + } + + $url->setAbsolute(); + if (!$url->isExternal()) { + $url->setRouteParameter('_format', 'iiif-p-v3'); + } + $generated_url = $url->toString(TRUE); + $this->addCacheableDependency($context, $generated_url); + + return $generated_url->getGeneratedUrl(); + } + +} diff --git a/src/Normalizer/RouterProviderTrait.php b/src/Normalizer/RouterProviderTrait.php new file mode 100644 index 0000000..0024487 --- /dev/null +++ b/src/Normalizer/RouterProviderTrait.php @@ -0,0 +1,41 @@ +routeProvider)) { + $this->routeProvider = \Drupal::service('router.route_provider'); + } + return $this->routeProvider; + } + + /** + * Set the route provider service. + * + * @param \Drupal\Core\Routing\RouteProviderInterface $routeProvider + * The route provider service. + */ + protected function setRouteProvider(RouteProviderInterface $routeProvider): void { + $this->routeProvider = $routeProvider; + } + +} diff --git a/src/Normalizer/V3/ContentEntityNormalizer.php b/src/Normalizer/V3/ContentEntityNormalizer.php index 0718788..628d92c 100644 --- a/src/Normalizer/V3/ContentEntityNormalizer.php +++ b/src/Normalizer/V3/ContentEntityNormalizer.php @@ -4,13 +4,17 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\iiif_presentation_api\Normalizer\EntityUriTrait; /** * Normalizer for content entities. */ class ContentEntityNormalizer extends NormalizerBase { + use EntityUriTrait; + /** * {@inheritDoc} */ @@ -28,9 +32,12 @@ class ContentEntityNormalizer extends NormalizerBase { * * @param \Drupal\Core\Session\AccountInterface $user * The current user. + * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider + * The route provider service. */ - public function __construct(AccountInterface $user) { + public function __construct(AccountInterface $user, RouteProviderInterface $route_provider) { $this->user = $user; + $this->setRouteProvider($route_provider); } /** @@ -39,7 +46,7 @@ public function __construct(AccountInterface $user) { public function normalize($object, $format = NULL, array $context = []) { $normalized = []; - if (empty($context)) { + if (!isset($context['base-depth'])) { $context['base-depth'] = TRUE; $normalized['@context'] = 'http://iiif.io/api/presentation/3/context.json'; } @@ -50,7 +57,7 @@ public function normalize($object, $format = NULL, array $context = []) { 'id' => $this->getEntityUri($object, $context), 'type' => $context['base-depth'] ? 'Manifest' : 'Canvas', 'label' => [ - $object->language()->getId() => [$object->label()], + 'none' => [$object->label()], ], ]; @@ -84,7 +91,7 @@ public function normalize($object, $format = NULL, array $context = []) { * @return array * The normalized representation of the entity. */ - protected function normalizeEntityFields(ContentEntityInterface $object, string $format, array $context, array $normalized) { + protected function normalizeEntityFields(ContentEntityInterface $object, string $format, array $context, array $normalized): array { $this->addCacheableDependency($context, $object); foreach ($object->getFields() as $field) { $access = $field->access('view', $context['account'], TRUE); diff --git a/src/Normalizer/V3/NormalizerBase.php b/src/Normalizer/V3/NormalizerBase.php index 51bceff..7fabc1e 100644 --- a/src/Normalizer/V3/NormalizerBase.php +++ b/src/Normalizer/V3/NormalizerBase.php @@ -2,8 +2,6 @@ namespace Drupal\iiif_presentation_api\Normalizer\V3; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Url; use Drupal\serialization\Normalizer\NormalizerBase as SerializationNormalizerBase; /** @@ -41,43 +39,6 @@ protected function checkFormat($format = NULL) { return $format === $this->format; } - /** - * Constructs the entity URI. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity. - * @param array $context - * Normalization/serialization context. - * - * @return string - * The entity URI. - */ - protected function getEntityUri(EntityInterface $entity, array $context = []) { - // Some entity types don't provide a canonical link template. - if ($entity->isNew()) { - return ''; - } - - $route_name = 'rest.entity.' . $entity->getEntityTypeId() . '.GET'; - if ($entity->hasLinkTemplate('canonical')) { - $url = $entity->toUrl('canonical'); - } - elseif (\Drupal::service('router.route_provider')->getRoutesByNames([$route_name])) { - $url = Url::fromRoute('rest.entity.' . $entity->getEntityTypeId() . '.GET', [$entity->getEntityTypeId() => $entity->id()]); - } - else { - return ''; - } - - $url->setAbsolute(); - if (!$url->isExternal()) { - $url->setRouteParameter('_format', 'iiif-p-v3'); - } - $generated_url = $url->toString(TRUE); - $this->addCacheableDependency($context, $generated_url); - return $generated_url->getGeneratedUrl(); - } - /** * {@inheritdoc} */ From 8b97a5fe962aa17dee61ced1626a9d479d6900d6 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Fri, 15 Sep 2023 10:30:30 -0300 Subject: [PATCH 4/8] Unneeded injection. --- iiif_presentation_api.services.yml | 2 +- src/Normalizer/V3/ContentEntityNormalizer.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/iiif_presentation_api.services.yml b/iiif_presentation_api.services.yml index 51bcd3e..05b3c1e 100644 --- a/iiif_presentation_api.services.yml +++ b/iiif_presentation_api.services.yml @@ -7,7 +7,7 @@ services: class: 'Drupal\iiif_presentation_api\Normalizer\V3\ContentEntityNormalizer' tags: - { name: normalizer, priority: 10 } - arguments: ['@current_user', '@router.route_provider'] + arguments: ['@current_user'] serializer.normalizer.iiif_presentation_api.iiif_p_v3.field_item_list: class: 'Drupal\iiif_presentation_api\Normalizer\V3\FieldItemListNormalizer' tags: diff --git a/src/Normalizer/V3/ContentEntityNormalizer.php b/src/Normalizer/V3/ContentEntityNormalizer.php index 628d92c..5e8b0ed 100644 --- a/src/Normalizer/V3/ContentEntityNormalizer.php +++ b/src/Normalizer/V3/ContentEntityNormalizer.php @@ -32,12 +32,9 @@ class ContentEntityNormalizer extends NormalizerBase { * * @param \Drupal\Core\Session\AccountInterface $user * The current user. - * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider - * The route provider service. */ - public function __construct(AccountInterface $user, RouteProviderInterface $route_provider) { + public function __construct(AccountInterface $user) { $this->user = $user; - $this->setRouteProvider($route_provider); } /** From 07f37404088c31b9e8c4a44fa862b30d613faa4f Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 19 Sep 2023 09:40:25 -0300 Subject: [PATCH 5/8] Unused use. --- src/Normalizer/V3/ContentEntityNormalizer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Normalizer/V3/ContentEntityNormalizer.php b/src/Normalizer/V3/ContentEntityNormalizer.php index 5e8b0ed..969b102 100644 --- a/src/Normalizer/V3/ContentEntityNormalizer.php +++ b/src/Normalizer/V3/ContentEntityNormalizer.php @@ -4,7 +4,6 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Session\AccountInterface; use Drupal\iiif_presentation_api\Normalizer\EntityUriTrait; From 38d60093cccaf51c48f20e154feaa5ea567913a5 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 19 Sep 2023 10:51:48 -0300 Subject: [PATCH 6/8] Add semver + lint. --- .github/workflows/lint.yml | 11 +++++++++++ .github/workflows/semver.yml | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/semver.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..06cda86 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,11 @@ +--- +name: Code Linting +on: + pull_request: + branches: + - ${main_branch} + workflow_dispatch: + +jobs: + Lint: + uses: discoverygarden/CodeSniffer/.github/workflows/lint.yml@v1 diff --git a/.github/workflows/semver.yml b/.github/workflows/semver.yml new file mode 100644 index 0000000..f758064 --- /dev/null +++ b/.github/workflows/semver.yml @@ -0,0 +1,12 @@ +--- +name: Semantic Version Tagging +on: + pull_request_target: + types: closed + branches: + - ${main_branch} + +jobs: + tag_update: + name: Tag Update + uses: discoverygarden/auto-semver/.github/workflows/semver.yml@v1 From 2b6fc4348e4e3b94d322d2975c27bb8e9fb69f0a Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 19 Sep 2023 11:26:27 -0300 Subject: [PATCH 7/8] No variable. --- .github/workflows/lint.yml | 2 +- .github/workflows/semver.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 06cda86..091b703 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,7 +3,7 @@ name: Code Linting on: pull_request: branches: - - ${main_branch} + - main workflow_dispatch: jobs: diff --git a/.github/workflows/semver.yml b/.github/workflows/semver.yml index f758064..7a9c768 100644 --- a/.github/workflows/semver.yml +++ b/.github/workflows/semver.yml @@ -4,7 +4,7 @@ on: pull_request_target: types: closed branches: - - ${main_branch} + - main jobs: tag_update: From 6062c3453a1a4fc03629d009a0e1a0252ce2a367 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 19 Sep 2023 11:41:22 -0300 Subject: [PATCH 8/8] CS. --- src/IiifPresentationApiServiceProvider.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/IiifPresentationApiServiceProvider.php b/src/IiifPresentationApiServiceProvider.php index 5dfabac..a5d8e08 100644 --- a/src/IiifPresentationApiServiceProvider.php +++ b/src/IiifPresentationApiServiceProvider.php @@ -5,6 +5,9 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceModifierInterface; +/** + * Adds the iiif-p-v3 format to be available to be requested. + */ class IiifPresentationApiServiceProvider implements ServiceModifierInterface { /** @@ -12,7 +15,10 @@ class IiifPresentationApiServiceProvider implements ServiceModifierInterface { */ public function alter(ContainerBuilder $container) { if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), '\Drupal\Core\StackMiddleware\NegotiationMiddleware', TRUE)) { - $container->getDefinition('http_middleware.negotiation')->addMethodCall('registerFormat', ['iiif-p-v3', ['application/json']]); + $container->getDefinition('http_middleware.negotiation')->addMethodCall('registerFormat', [ + 'iiif-p-v3', + ['application/json'], + ]); } }