From 42856c6d9e1a9d0c91ca4093db700268fd3660e8 Mon Sep 17 00:00:00 2001 From: berliner Date: Sat, 11 Nov 2023 00:30:43 +0100 Subject: [PATCH] HPC-9191: Fix regression in article search --- .../src/ContentManager/BaseContentManager.php | 2 +- .../ghi_hero_image/src/HeroImageManager.php | 20 +++++++++++++++++-- .../FieldFormatter/HeroImageFormatter.php | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/html/modules/custom/ghi_content/src/ContentManager/BaseContentManager.php b/html/modules/custom/ghi_content/src/ContentManager/BaseContentManager.php index 8b653a985..03a0e82ae 100644 --- a/html/modules/custom/ghi_content/src/ContentManager/BaseContentManager.php +++ b/html/modules/custom/ghi_content/src/ContentManager/BaseContentManager.php @@ -717,7 +717,7 @@ public function nodeEditFormAlter(array &$form, FormStateInterface $form_state) $form['remote_content_info']['status'] = [ '#type' => 'item', '#title' => $this->t('Up to date'), - '#markup' => '

' . $this->t('This @label page is up to date with its source content on the remote system.', $t_args) . '

', + '#markup' => '

' . $this->t('This @label is up to date with its source content on the remote system.', $t_args) . '

', '#weight' => 1, ]; diff --git a/html/modules/custom/ghi_hero_image/src/HeroImageManager.php b/html/modules/custom/ghi_hero_image/src/HeroImageManager.php index 77a8a49e0..fa5bebc18 100644 --- a/html/modules/custom/ghi_hero_image/src/HeroImageManager.php +++ b/html/modules/custom/ghi_hero_image/src/HeroImageManager.php @@ -46,6 +46,22 @@ public function __construct(EndpointQueryManager $endpoint_query_manager, Image $this->fileSystem = $file_system; } + /** + * Get the default item source. + * + * @param \Drupal\Core\Field\FieldItemListInterface $items + * The field values to be rendered. + * + * @return string + * The item source as a string. + */ + public function getDefaultItemSource(FieldItemListInterface $items) { + if ($this->getPlanWebContentAttachments($items)) { + return 'hpc_webcontent_file_attachment'; + } + return 'none'; + } + /** * Get properties for a hero image. * @@ -65,8 +81,8 @@ public function getImageProperties(FieldItemListInterface $items, FormatterInter $item = !$items->isEmpty() ? (object) $items->get(0)->getValue() ?? NULL : NULL; $item_source = $item ? $item->source : NULL; - if (!$item_source && $attachments = $this->getPlanWebContentAttachments($items)) { - $item_source = 'hpc_webcontent_file_attachment'; + if (!$item_source) { + $item_source = $this->getDefaultItemSource($items); } $item_settings = $item && property_exists($item, 'settings') && is_array($item->settings) ? ($item->settings[$item_source] ?? []) : []; diff --git a/html/modules/custom/ghi_hero_image/src/Plugin/Field/FieldFormatter/HeroImageFormatter.php b/html/modules/custom/ghi_hero_image/src/Plugin/Field/FieldFormatter/HeroImageFormatter.php index 25fb5176a..b14c1667c 100644 --- a/html/modules/custom/ghi_hero_image/src/Plugin/Field/FieldFormatter/HeroImageFormatter.php +++ b/html/modules/custom/ghi_hero_image/src/Plugin/Field/FieldFormatter/HeroImageFormatter.php @@ -105,8 +105,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $entity = $items->getEntity(); $item = !$items->isEmpty() ? (object) $items->get(0)->getValue() ?? NULL : NULL; $item_source = $item ? $item->source : NULL; - if (!$item_source && $this->getPlanWebContentAttachments($items)) { - $item_source = 'hpc_webcontent_file_attachment'; + if (!$item_source) { + $item_source = $this->heroImageManager->getDefaultItemSource($items); } if ($item_source == 'inherit') {