From 9e0d87447f80b65e3e19d887d5fdda47fd4daac7 Mon Sep 17 00:00:00 2001 From: Chris Burgess Date: Tue, 29 Oct 2024 05:38:13 +1300 Subject: [PATCH] islandora#1059: Prevent error when Media lacks a File (#1060) --- 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])) {