diff --git a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php index 3c0683e..fd31d33 100644 --- a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php +++ b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php @@ -2,7 +2,6 @@ namespace Drupal\content_moderation\Plugin\Field; -use Drupal\content_moderation\ContentModerationStateInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Field\FieldItemList; @@ -48,7 +47,7 @@ protected function getModerationStateId() { * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity the content moderation state entity will be loaded from. * - * @return \Drupal\content_moderation\Entity\ContentModerationState|null + * @return \Drupal\content_moderation\ContentModerationStateInterface|null * The content_moderation_state revision or FALSE if none exists. */ protected function loadContentModerationStateRevision(ContentEntityInterface $entity) { @@ -66,19 +65,21 @@ protected function loadContentModerationStateRevision(ContentEntityInterface $en ->sort('revision_id', 'DESC') ->execute(); if (empty($revisions)) { - return null; + return NULL; } + /** @var \Drupal\content_moderation\ContentModerationStateInterface $content_moderation_state */ $content_moderation_state = $content_moderation_storage->loadRevision(key($revisions)); - if (!$entity->getEntityType()->hasKey('langcode')) { - return $content_moderation_state; - } - - $langcode = $entity->language()->getId(); - if (!$content_moderation_state->hasTranslation($langcode)) { - $content_moderation_state->addTranslation($langcode); + if ($entity->getEntityType()->hasKey('langcode')) { + $langcode = $entity->language()->getId(); + if (!$content_moderation_state->hasTranslation($langcode)) { + $content_moderation_state->addTranslation($langcode); + } + if ($content_moderation_state->language()->getId() !== $langcode) { + $content_moderation_state = $content_moderation_state->getTranslation($langcode); + } } - return $content_moderation_state->language()->getId() !== $langcode ? $content_moderation_state->getTranslation($langcode) : $content_moderation_state; + return $content_moderation_state; } /**