From 492be9fdefc69069547c61aeb7c4e6f1df02a176 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Wed, 30 Jun 2021 13:18:00 -0300 Subject: [PATCH] Issue #1848 EmitFileEvent.php: Call to undefined function getFileUri() (#838) Explicitly check for function before it is called. --- src/Plugin/Action/EmitFileEvent.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Plugin/Action/EmitFileEvent.php b/src/Plugin/Action/EmitFileEvent.php index a749a2a4..cd20b3d5 100644 --- a/src/Plugin/Action/EmitFileEvent.php +++ b/src/Plugin/Action/EmitFileEvent.php @@ -105,18 +105,22 @@ class EmitFileEvent extends EmitEvent { * {@inheritdoc} */ protected function generateData(EntityInterface $entity) { - $uri = $entity->getFileUri(); - $scheme = StreamWrapperManager::getScheme($uri); - $flysystem_config = Settings::get('flysystem'); - $data = parent::generateData($entity); - if (isset($flysystem_config[$scheme]) && $flysystem_config[$scheme]['driver'] == 'fedora') { - // Fdora $uri for files may contain ':///' so we need to replace - // the three / with two. - if (strpos($uri, $scheme . ':///') !== FALSE) { - $uri = str_replace($scheme . ':///', $scheme . '://', $uri); + + // This function is called on Media and File entity types. + if (method_exists($entity, 'getFileUri')) { + $uri = $entity->getFileUri(); + $scheme = StreamWrapperManager::getScheme($uri); + $flysystem_config = Settings::get('flysystem'); + + if (isset($flysystem_config[$scheme]) && $flysystem_config[$scheme]['driver'] == 'fedora') { + // Fdora $uri for files may contain ':///' so we need to replace + // the three / with two. + if (strpos($uri, $scheme . ':///') !== FALSE) { + $uri = str_replace($scheme . ':///', $scheme . '://', $uri); + } + $data['fedora_uri'] = str_replace("$scheme://", $flysystem_config[$scheme]['config']['root'], $uri); } - $data['fedora_uri'] = str_replace("$scheme://", $flysystem_config[$scheme]['config']['root'], $uri); } return $data; }