Skip to content

Commit

Permalink
Add cache metadata, and fix array offsets...
Browse files Browse the repository at this point in the history
... apparently, is strict about the keys being numeric.
  • Loading branch information
adam-vessey committed Jun 19, 2023
1 parent 86daf66 commit 7013307
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Plugin/Field/FieldFormatter/MiradorImageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\islandora_mirador\Plugin\Field\FieldFormatter;

use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
Expand Down Expand Up @@ -119,21 +120,29 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
if (empty($files)) {
return $elements;
}

$iiif_url = $this->configFactory->get('islandora_mirador.settings')->get('iiif_manifest_url');
$token_service = $this->token;
foreach ($files as $file) {
$cache_meta = CacheableMetadata::createFromObject($file);

$medias = $this->utils->getReferencingMedia($file->id());
$first_media = array_values($medias)[0];
$cache_meta->addCacheableDependency($first_media);
$node = $first_media->get('field_media_of')->entity;
$cache_meta->addCacheableDependency($node);
$id = 'mirador_' . $node->id();
$manifest_url = $token_service->replace($iiif_url, ['node' => $node]);
$elements[$id] = [
$renderable = [
'#theme' => 'mirador',
'#mirador_view_id' => $id,
'#iiif_manifest_url' => $manifest_url,
'#settings' => $settings,
];
$cache_meta->applyTo($renderable);
$elements[] = $renderable;
}

return $elements;
}

Expand Down

0 comments on commit 7013307

Please sign in to comment.