public function EntityOperations::entityPresave in Config Entity Revisions 8.2
Acts on an entity and set published status based on the moderation state.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity being saved.
See also
File
- src/
EntityOperations.php, line 105
Class
- EntityOperations
- Defines a class for reacting to entity events.
Namespace
Drupal\config_entity_revisionsCode
public function entityPresave(EntityInterface $entity) {
if (!$this->moderationInfo
->isModeratedEntity($entity)) {
return;
}
$revisioned_entity = $entity instanceof ConfigEntityRevisionsConfigEntityInterface ? $entity
->getContentEntity() : $entity;
if ($entity->moderation_state) {
$workflow = $this->moderationInfo
->getWorkflowForEntity($revisioned_entity);
/** @var \Drupal\content_moderation\ContentModerationState $current_state */
$current_state = $workflow
->getTypePlugin()
->getState($entity->moderation_state->value);
// This entity is default if it is new, the default revision, or the
// default revision is not published.
$update_default_revision = $entity
->isNew() || $current_state
->isDefaultRevisionState() || !$this->moderationInfo
->isDefaultRevisionPublished($revisioned_entity);
// Fire per-entity-type logic for handling the save process.
$this->entityTypeManager
->getHandler($entity
->getEntityTypeId(), 'moderation')
->onPresave($revisioned_entity, $update_default_revision, $current_state
->isPublishedState());
}
}