Skip to content

Commit

Permalink
Some docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Nov 21, 2023
1 parent f36c459 commit 42be2b0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ provided normalizers.
For any content entity that should be exposed the format will need to be
configured as [documented by Drupal][1].

There are some environment variables to help integrate with IIIF Image APIs, in particular:

| Variable | Description |
|----------------------|---------------------------------------------------------------------------------------------------|
| `IIIF_IMAGE_V1_SLUG` | Slug to a IIIF v1 endpoint, containing `{identifier}`, which will be replaced with an identifier. |
| `IIIF_IMAGE_V2_SLUG` | Slug to a IIIF v2 endpoint, containing `{identifier}`, which will be replaced with an identifier. |
| `IIIF_IMAGE_V3_SLUG` | Slug to a IIIF v3 endpoint, containing `{identifier}`, which will be replaced with an identifier. |
| `IIIF_IMAGE_ID_PLUGIN` | The ID of a plugin to use to transform IDs. |

Presently, we indicate `level2` compliance for each IIIF Image API endpoint.

## Troubleshooting/Issues

Having problems or solved one? contact
Expand Down
46 changes: 42 additions & 4 deletions src/EventSubscriber/V3/BaseImageBodyEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
use Drupal\iiif_presentation_api\Event\V3\ImageBodyEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* IIIF Image API body generator.
*/
class BaseImageBodyEventSubscriber implements EventSubscriberInterface {

/**
* Constructor.
*/
public function __construct(
protected PluginManagerInterface $idPluginManager
) {
Expand All @@ -20,23 +26,43 @@ public function __construct(
public static function getSubscribedEvents() {
return [
ImageBodyEvent::class => [
['baseBody', 100],
['imageV1Body', 55],
['imageV2Body', 50],
['imageV3Body', 45],
['imageV3Body', 100],
['imageV2Body', 75],
['imageV1Body', 50],
['baseBody', 25],
],
];
}

/**
* Event callback; build base body without IIIF Image API.
*/
public function baseBody(ImageBodyEvent $event) : void {
$file = $event->getImage();
$event->addBody([
'id' => $file->createFileUrl(FALSE),
'type' => 'Image',
'format' => $file->getMimeType(),
'service' => [],
]);
}

/**
* Build out a body.
*
* @param string|null $slug
* A URL slug for the endpoint. If provided, should have an `{identifier}`
* portion that we will replace with an ID.
* @param \Drupal\file\FileInterface $file
* The file for which to generate a bod.
* @param array $extra
* An associative array of extra values to be set in the body.
*
* @return array
* The body.
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
protected function getBody(?string $slug, FileInterface $file, array $extra = []) : array {
if (!$slug) {
return [];
Expand All @@ -48,6 +74,7 @@ protected function getBody(?string $slug, FileInterface $file, array $extra = []
]);
return [
'id' => "$base_id/full/full/0/default.jpg",
'type' => 'Image',
'format' => 'image/jpeg',
'service' => [
[
Expand All @@ -65,6 +92,9 @@ protected function getBody(?string $slug, FileInterface $file, array $extra = []
];
}

/**
* Event callback; build body for IIIF Image API v1.
*/
public function imageV1Body(ImageBodyEvent $event) : void {
$event->addBody($this->getBody(
getenv('IIIF_IMAGE_V1_SLUG'),
Expand All @@ -75,6 +105,10 @@ public function imageV1Body(ImageBodyEvent $event) : void {
],
));
}

/**
* Event callback; build body for IIIF Image API v2.
*/
public function imageV2Body(ImageBodyEvent $event) : void {
$event->addBody($this->getBody(
getenv('IIIF_IMAGE_V2_SLUG'),
Expand All @@ -85,6 +119,10 @@ public function imageV2Body(ImageBodyEvent $event) : void {
],
));
}

/**
* Event callback; build body for IIIF Image API v3.
*/
public function imageV3Body(ImageBodyEvent $event) : void {
$event->addBody($this->getBody(
getenv('IIIF_IMAGE_V3_SLUG'),
Expand Down

0 comments on commit 42be2b0

Please sign in to comment.