From 96cb4f2cc445a43cf9d4aa97d7b4b25b4f471cbb Mon Sep 17 00:00:00 2001 From: ajstanley Date: Wed, 26 Jun 2024 13:55:57 -0300 Subject: [PATCH 1/5] added check --- islandora.module | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/islandora.module b/islandora.module index 8fa478a7f..ed1abb43e 100644 --- a/islandora.module +++ b/islandora.module @@ -549,10 +549,8 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie $mapper = \Drupal::service('islandora.entity_mapper'); $flysystem_config = Settings::get('flysystem'); $fedora_root = $flysystem_config['fedora']['config']['root']; - $fedora_root = rtrim($fedora_root, '/'); - if ($entity->getEntityTypeId() == 'media') { - // Check if the source file is in Fedora or not. + // Check existence of source file. $media_source_service = \Drupal::service('islandora.media_source_service'); $source_file = $media_source_service->getSourceFile($entity); if (!$source_file) { @@ -566,6 +564,10 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie ); return; } + if (!$fedora_root) { + return; + } + $fedora_root = rtrim($fedora_root, '/'); $uri = $source_file->getFileUri(); $scheme = \Drupal::service('stream_wrapper_manager')->getScheme($uri); $flysystem_config = Settings::get('flysystem'); @@ -584,6 +586,9 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie } else { // All non-media entities do the UUID -> pair tree thang. + if (!$fedora_root) { + return; + } $path = $mapper->getFedoraPath($entity->uuid()); $path = trim($path, '/'); $fedora_uri = "$fedora_root/$path"; @@ -608,7 +613,6 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie } } } - /** * Implements hook_preprocess_views_view_table(). * From de2f62e53ce5e78a7df7ecae5dcdeffeaf41f269 Mon Sep 17 00:00:00 2001 From: ajstanley Date: Wed, 26 Jun 2024 14:20:54 -0300 Subject: [PATCH 2/5] blank line --- islandora.module | 1 + 1 file changed, 1 insertion(+) diff --git a/islandora.module b/islandora.module index ed1abb43e..656c9c475 100644 --- a/islandora.module +++ b/islandora.module @@ -613,6 +613,7 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie } } } + /** * Implements hook_preprocess_views_view_table(). * From 9a8a7b6fd68b7796f8057a0cf9d37f17f0c462a5 Mon Sep 17 00:00:00 2001 From: ajstanley Date: Wed, 26 Jun 2024 14:30:35 -0300 Subject: [PATCH 3/5] cleaner implementation --- islandora.module | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/islandora.module b/islandora.module index 656c9c475..9f7c5d421 100644 --- a/islandora.module +++ b/islandora.module @@ -545,12 +545,13 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie $route_match_item = \Drupal::routeMatch()->getParameters()->get($entity->getEntityTypeId()); // Ensure the entity matches the route. if ($entity === $route_match_item) { - if ($display->getComponent('field_gemini_uri')) { + $flysystem_config = Settings::get('flysystem'); + $fedora_root = $flysystem_config['fedora']['config']['root']; + $fedora_root = rtrim($fedora_root, '/'); + if ($display->getComponent('field_gemini_uri') && $fedora_root) { $mapper = \Drupal::service('islandora.entity_mapper'); - $flysystem_config = Settings::get('flysystem'); - $fedora_root = $flysystem_config['fedora']['config']['root']; if ($entity->getEntityTypeId() == 'media') { - // Check existence of source file. + // Check if the source file is in Fedora or not. $media_source_service = \Drupal::service('islandora.media_source_service'); $source_file = $media_source_service->getSourceFile($entity); if (!$source_file) { @@ -564,10 +565,6 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie ); return; } - if (!$fedora_root) { - return; - } - $fedora_root = rtrim($fedora_root, '/'); $uri = $source_file->getFileUri(); $scheme = \Drupal::service('stream_wrapper_manager')->getScheme($uri); $flysystem_config = Settings::get('flysystem'); @@ -586,9 +583,6 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie } else { // All non-media entities do the UUID -> pair tree thang. - if (!$fedora_root) { - return; - } $path = $mapper->getFedoraPath($entity->uuid()); $path = trim($path, '/'); $fedora_uri = "$fedora_root/$path"; From 33e5e7388c217d0fe3ce4ef11f0e82664b94bd36 Mon Sep 17 00:00:00 2001 From: ajstanley Date: Wed, 26 Jun 2024 15:23:58 -0300 Subject: [PATCH 4/5] check added --- islandora.module | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/islandora.module b/islandora.module index 9f7c5d421..58403af5c 100644 --- a/islandora.module +++ b/islandora.module @@ -546,8 +546,11 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie // Ensure the entity matches the route. if ($entity === $route_match_item) { $flysystem_config = Settings::get('flysystem'); - $fedora_root = $flysystem_config['fedora']['config']['root']; - $fedora_root = rtrim($fedora_root, '/'); + $fedora_root = NULL; + if (isset($flysystem_config['fedora']['config']['root'])) { + $fedora_root = $flysystem_config['fedora']['config']['root']; + $fedora_root = rtrim($fedora_root, '/'); + } if ($display->getComponent('field_gemini_uri') && $fedora_root) { $mapper = \Drupal::service('islandora.entity_mapper'); if ($entity->getEntityTypeId() == 'media') { From 146bd564d79aeb80aa2283e764682633ae563129 Mon Sep 17 00:00:00 2001 From: ajstanley Date: Wed, 26 Jun 2024 16:04:15 -0300 Subject: [PATCH 5/5] tidied up --- islandora.module | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/islandora.module b/islandora.module index 58403af5c..153eb1679 100644 --- a/islandora.module +++ b/islandora.module @@ -546,12 +546,9 @@ function islandora_entity_view(array &$build, EntityInterface $entity, EntityVie // Ensure the entity matches the route. if ($entity === $route_match_item) { $flysystem_config = Settings::get('flysystem'); - $fedora_root = NULL; - if (isset($flysystem_config['fedora']['config']['root'])) { - $fedora_root = $flysystem_config['fedora']['config']['root']; - $fedora_root = rtrim($fedora_root, '/'); - } + $fedora_root = $flysystem_config['fedora']['config']['root'] ?? NULL; if ($display->getComponent('field_gemini_uri') && $fedora_root) { + $fedora_root = rtrim($fedora_root, '/'); $mapper = \Drupal::service('islandora.entity_mapper'); if ($entity->getEntityTypeId() == 'media') { // Check if the source file is in Fedora or not.