From 0907e92478ae896ee6054b6c8f53a33a9b01ef55 Mon Sep 17 00:00:00 2001 From: Andy Broomfield Date: Tue, 30 Apr 2024 22:24:08 +0100 Subject: [PATCH] Fix Translation for alert banner not displaying Originally authoured by [adinancenci](https://www.drupal.org/u/adinancenci). Applies patch in comment 3. https://www.drupal.org/project/localgov/issues/3427615#comment-15487385 --- src/Entity/AlertBannerEntity.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Entity/AlertBannerEntity.php b/src/Entity/AlertBannerEntity.php index 1fbab7e..aadb0da 100644 --- a/src/Entity/AlertBannerEntity.php +++ b/src/Entity/AlertBannerEntity.php @@ -250,14 +250,19 @@ public function setOwner(UserInterface $account) { * True if the alert banner is visible, otherwise FALSE. */ public function isVisible() { + $entity = $this; + $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); + if ($langcode != 'en' && $this->hasTranslation($langcode)) { + $entity = $this->getTranslation($langcode); + } // Check if the field is present and has a value. - if (!$this->hasField('visibility') || $this->get('visibility')->isEmpty()) { + if (!$entity->hasField('visibility') || $entity->get('visibility')->isEmpty()) { return TRUE; } // Visibility condition config. - $conditions_config = $this->get('visibility')->getValue()[0]['conditions']; + $conditions_config = $entity->get('visibility')->getValue()[0]['conditions']; // Construct visibility conditions. $conditions = [];