From 4a86d6738e7af26f278c645f43ebff95ff2f0836 Mon Sep 17 00:00:00 2001
From: orybak <orybak@3124549.no-reply.drupal.org>
Date: Wed, 19 May 2021 14:06:21 +0000
Subject: [PATCH] Issue #3041513 by Olga Rybak: Translation status isn't
 respected in isPublished()

---
 src/Entity/Widget.php | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/Entity/Widget.php b/src/Entity/Widget.php
index bb8e0f4..3d9e9bb 100644
--- a/src/Entity/Widget.php
+++ b/src/Entity/Widget.php
@@ -145,7 +145,23 @@ class Widget extends ContentEntityBase implements WidgetInterface {
    * {@inheritdoc}
    */
   public function isPublished() {
-    return (bool) $this->getEntityKey('status');
+    // Get current language.
+    $lang = $this->languageManager()->getCurrentLanguage()->getId();
+    $is_published = (bool) $this->getEntityKey('status');
+
+    // Check if translation exists.
+    if (!$this->hasTranslation($lang)) {
+      return $is_published;
+    }
+
+    $translation = $this->getTranslation($lang);
+    if (is_null($translation) || !$translation->hasField('content_translation_status')) {
+      return $is_published;
+    }
+    // Get translation status.
+    $t_status = (bool) $translation->getTranslationStatus($lang) && $translation->get('content_translation_status')->value;
+
+    return $t_status && $is_published;
   }
 
   /**
-- 
GitLab