diff --git a/src/Event/V3/ImageBodyEvent.php b/src/Event/V3/ImageBodyEvent.php index c7fcca6..3bab5b5 100644 --- a/src/Event/V3/ImageBodyEvent.php +++ b/src/Event/V3/ImageBodyEvent.php @@ -22,6 +22,7 @@ class ImageBodyEvent extends Event { */ public function __construct( protected FileInterface $image, + protected string $size = 'full', ) { } @@ -58,4 +59,14 @@ public function getBodies() : array { return $this->bodies; } + /** + * Get the requested size hint. + * + * @return string + * The size hint requested for the event. + */ + public function getSize() : string { + return $this->size; + } + } diff --git a/src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php b/src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php index 972b102..29ead87 100644 --- a/src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php +++ b/src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php @@ -57,13 +57,15 @@ public function baseBody(ImageBodyEvent $event) : void { * The file for which to generate a bod. * @param array $extra * An associative array of extra values to be set in the body. + * @param string $size + * The requested size. * * @return array * The body. * * @throws \Drupal\Component\Plugin\Exception\PluginException */ - protected function getBody(?string $slug, FileInterface $file, array $extra = []) : array { + protected function getBody(?string $slug, FileInterface $file, array $extra = [], string $size = 'full') : array { if (!$slug) { return []; } @@ -73,7 +75,7 @@ protected function getBody(?string $slug, FileInterface $file, array $extra = [] '{identifier}' => rawurlencode($id_plugin->getIdentifier($file)), ]); return [ - 'id' => "$base_id/full/full/0/default.jpg", + 'id' => "{$base_id}/full/{$size}/0/default.jpg", 'type' => 'Image', 'format' => 'image/jpeg', 'service' => [ @@ -96,6 +98,9 @@ public function imageV1Body(ImageBodyEvent $event) : void { 'type' => 'ImageService1', 'profile' => 'level2', ], + // @todo Validate that the size spec is valid for IIIF-I V1, maybe map to + // something similar if unsupported? + $event->getSize(), )); } @@ -110,6 +115,9 @@ public function imageV2Body(ImageBodyEvent $event) : void { 'type' => 'ImageService2', 'profile' => 'level2', ], + // @todo Validate that the size spec is valid for IIIF-I V2, maybe map to + // something similar if unsupported? + $event->getSize(), )); } @@ -124,6 +132,9 @@ public function imageV3Body(ImageBodyEvent $event) : void { 'type' => 'ImageService3', 'profile' => 'level2', ], + // @todo Validate that the size spec is valid for IIIF-I V3, maybe map to + // something similar if unsupported? + $event->getSize(), )); }