/**
* Creates or updates the moderation state of an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to update or create a moderation state for.
*/
protected function updateOrCreateFromEntity(EntityInterface
$entity) { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity_revision_id =
$entity->
getRevisionId();
$workflow =
$this->moderationInfo->
getWorkflowForEntity($entity);
$content_moderation_state = ContentModerationStateEntity::
loadFromModeratedEntity($entity);
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
$storage =
$this->entityTypeManager->
getStorage('content_moderation_state'
);
if (!
($content_moderation_state instanceof ContentModerationStateInterface
)) { $content_moderation_state =
$storage->
create([ 'content_entity_type_id' =>
$entity->
getEntityTypeId(),
'content_entity_id' =>
$entity->
id(),
// Make sure that the moderation state entity has the same language code
// as the moderated entity.
'langcode' =>
$entity->
language()->
getId(),
]);