From 2ef16ebd7d57c8a5261fa4306f3453fbab900149 Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Thu, 17 Oct 2024 13:10:22 +1300 Subject: [PATCH] islandora#1059: Prevent error when Media lacks a File --- src/Plugin/ContextReaction/JsonldSelfReferenceReaction.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Plugin/ContextReaction/JsonldSelfReferenceReaction.php b/src/Plugin/ContextReaction/JsonldSelfReferenceReaction.php index ed6aac95e..97454ca43 100644 --- a/src/Plugin/ContextReaction/JsonldSelfReferenceReaction.php +++ b/src/Plugin/ContextReaction/JsonldSelfReferenceReaction.php @@ -88,10 +88,11 @@ public function execute(EntityInterface $entity = NULL, array &$normalized = NUL if (isset($normalized['@graph']) && is_array($normalized['@graph'])) { foreach ($normalized['@graph'] as &$graph) { if (isset($graph['@id']) && $graph['@id'] == $url) { - // Swap media and file urls. + // If a file URL is available, swap it in as the ID. if ($entity instanceof MediaInterface) { - $file = $this->mediaSource->getSourceFile($entity); - $graph['@id'] = $this->utils->getDownloadUrl($file); + if ($file = $this->mediaSource->getSourceFile($entity)) { + $graph['@id'] = $this->utils->getDownloadUrl($file); + } } if (isset($graph[$self_ref_predicate])) { if (!is_array($graph[$self_ref_predicate])) {