-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DGIR-142 : Add thumbnail to manifest #7
Changes from all commits
d610e0a
84a5cdc
715c317
7426a5a
adb6a0d
306d40f
5ba121e
b7ff4d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -6,7 +6,9 @@ | |||
use Drupal\Core\Entity\ContentEntityInterface; | ||||
use Drupal\Core\Session\AccountInterface; | ||||
use Drupal\Core\Url; | ||||
use Drupal\file\FileInterface; | ||||
use Drupal\iiif_presentation_api\Event\V3\ContentEntityExtrasEvent; | ||||
use Drupal\iiif_presentation_api\Event\V3\ImageBodyEvent; | ||||
use Drupal\iiif_presentation_api\Normalizer\EntityUriTrait; | ||||
use Drupal\node\NodeInterface; | ||||
use Psr\EventDispatcher\EventDispatcherInterface; | ||||
|
@@ -106,9 +108,71 @@ public function normalize($object, $format = NULL, array $context = []) { | |||
$normalized = NestedArray::mergeDeep($normalized, $extras); | ||||
} | ||||
|
||||
// It triggers for node and media. Adds thumbnail multiple time. | ||||
// Restricting it for node only. | ||||
if ($object->getEntityTypeId() == 'node') { | ||||
|
||||
// Load the entity type manager. | ||||
$entity_type_manager = \Drupal::entityTypeManager(); | ||||
|
||||
// Get term id for Thumbnail Image. | ||||
$term_storage = $entity_type_manager->getStorage('taxonomy_term'); | ||||
$term = $term_storage->loadByProperties([ | ||||
'name' => 'Thumbnail Image', | ||||
'vid' => 'islandora_media_use', | ||||
]); | ||||
|
||||
// Check if the term is found. | ||||
if (!empty($term)) { | ||||
// Get the term ID. | ||||
$term_id = reset($term)->id(); | ||||
} | ||||
|
||||
// Get the storage handler for the media entity. | ||||
$media_storage = $entity_type_manager->getStorage('media'); | ||||
|
||||
// Load a single media entity by properties. | ||||
$media_entities = $media_storage->loadByProperties([ | ||||
'field_media_use' => $term_id, | ||||
'field_media_of' => $object->id(), | ||||
]); | ||||
|
||||
// Check if a media entity was found. | ||||
if ($media_entities) { | ||||
// Process the single media entity as needed. | ||||
$media_entity = reset($media_entities); | ||||
|
||||
// Get the file ID from the file field. | ||||
$file_id = $media_entity->get('field_media_image')->target_id; | ||||
$file = $entity_type_manager->getStorage('file')->load($file_id); | ||||
|
||||
$normalized['thumbnail'] = $this->generateBody($file); | ||||
} | ||||
} | ||||
Comment on lines
+111
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This module is not supposed to be aware of any Islandora-isms. Particular bindings to Islandora should be done in the Also, really kind of seems like this would fit as an event subscriber to the event already dispatched: https://github.com/discoverygarden/iiif_presentation_api/pull/7/files#diff-1f327eb453852f8fd88e233a026b713ce29fdbb5af1418b1f204f466a123e1f7R101-R109 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adam-vessey I will try to move the implementation to the Sorry if I am not clear above, I am trying to understand the implementation. I would be happy to get on a call to discuss same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unsure, that's what this ticket is (re)defining, no? Would have to go back to the reporter/project owner? Given the original notes referencing Really, I'm not sure what this ticket is trying to accomplish, seeming to conflate slow manifest generation with the dereferencing of entities described within the manifest. Sure, allowing it (Mirador) to use IIIF-I to generate thumbnails might consume some cycles on the server CPU side of things; however, given anticipated usage, it could be seen as cache warming (having the Cantaloupe/IIIF-I server acquire the images from which it will be serving tiles, but the IIIF-I-derived thumbnails could also be cached). Trying to use the "Thumbnail image(s)" requires all these additional queries in order to identify the media to provide as a thumbnail, for inclusion in the manifest, If we wanted to offer a mechanism to provide those related media/file with the "thumbnail": [
{
"id": "https://example.org/iiif/book1/page1/full/80,100/0/default.jpg",
"type": "Image",
"format": "image/jpeg",
"service": [
{
"id": "https://example.org/iiif/book1/page1",
"type": "ImageService3",
"profile": "level1"
}
]
}
], so, to add the
Something such as: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing code at We can discuss DGIR-142 once Luke is back. Thanks for providing code changes in feedback. |
||||
return $this->normalizeEntityFields($object, $format, $context, $normalized); | ||||
} | ||||
|
||||
/** | ||||
* Generate the annotation body. | ||||
* | ||||
* @param \Drupal\file\FileInterface $file | ||||
* The file for which to generate the body. | ||||
* | ||||
* @return array | ||||
* An associative array representing the body. | ||||
*/ | ||||
protected function generateBody(FileInterface $file) : array { | ||||
/** @var \Drupal\iiif_presentation_api\Event\V3\ImageBodyEvent $event */ | ||||
$event = $this->eventDispatcher->dispatch(new ImageBodyEvent($file)); | ||||
$bodies = $event->getBodies(); | ||||
if (!$bodies) { | ||||
return []; | ||||
} | ||||
$body = reset($bodies); | ||||
$body['service'] = array_merge(...array_filter(array_column($bodies, 'service'))); | ||||
return $body; | ||||
} | ||||
|
||||
/** | ||||
* Normalizes all fields present on a content entity. | ||||
* | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not able to add DI for this, it throws an error for circular dependency if I add EntityTypeManagerInterface.