/**
* Gets the moderation state ID linked to a content entity revision.
*
* @return string|null
* The moderation state ID linked to a content entity revision.
*/
protected function getModerationStateId() { $entity =
$this->
getEntity();
/** @var \Drupal\content_moderation\ModerationInformationInterface $moderation_info */
$moderation_info = \Drupal::
service('content_moderation.moderation_information'
);
if (!
$moderation_info->
shouldModerateEntitiesOfBundle($entity->
getEntityType(),
$entity->
bundle())) { return NULL;
} // Existing entities will have a corresponding content_moderation_state
// entity associated with them.
if (!
$entity->
isNew() &&
$content_moderation_state =
$this->
loadContentModerationStateRevision($entity)) { return $content_moderation_state->moderation_state->value;
} // It is possible that the bundle does not exist at this point. For example,
// the node type form creates a fake Node entity to get default values.