diff --git a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php index 9302662..3c0683e 100644 --- a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php +++ b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php @@ -32,7 +32,6 @@ protected function getModerationStateId() { // Existing entities will have a corresponding content_moderation_state // entity associated with them. if (!$entity->isNew() && $content_moderation_state = $this->loadContentModerationStateRevision($entity)) { - $content_moderation_state = $this->loadCorrespondingContentModerationStateLanguage($entity, $content_moderation_state); return $content_moderation_state->moderation_state->value; } @@ -44,28 +43,6 @@ protected function getModerationStateId() { } /** - * Load the correct language based on the language of the given entity. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity that will be used to determine the language loaded. - * @param \Drupal\content_moderation\ContentModerationStateInterface $content_moderation_state - * The entity whose language needs to match the given content entity. - * - * @return \Drupal\content_moderation\ContentModerationStateInterface - * The content moderation state entity matching the given language code. - */ - protected function loadCorrespondingContentModerationStateLanguage(ContentEntityInterface $entity, ContentModerationStateInterface $content_moderation_state) { - if (!$entity->getEntityType()->hasKey('langcode')) { - return $content_moderation_state; - } - $langcode = $entity->language()->getId(); - if (!$content_moderation_state->hasTranslation($langcode)) { - $content_moderation_state->addTranslation($langcode); - } - return $content_moderation_state->language()->getId() !== $langcode ? $content_moderation_state->getTranslation($langcode) : $content_moderation_state; - } - - /** * Load the content moderation state revision associated with an entity. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity @@ -88,8 +65,20 @@ protected function loadContentModerationStateRevision(ContentEntityInterface $en ->allRevisions() ->sort('revision_id', 'DESC') ->execute(); + if (empty($revisions)) { + return null; + } - return !empty($revisions) ? $content_moderation_storage->loadRevision(key($revisions)) : NULL; + $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); + } + return $content_moderation_state->language()->getId() !== $langcode ? $content_moderation_state->getTranslation($langcode) : $content_moderation_state; } /**