diff --git a/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php index 69410b1..b6153d2 100644 --- a/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php +++ b/core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php @@ -30,39 +30,6 @@ public static function createInstance(ContainerInterface $container, EntityTypeI /** * {@inheritdoc} */ - public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) { - if ($this->shouldModerate($entity, $published_state)) { - // This is probably not necessary if configuration is setup correctly. - $entity->setNewRevision(TRUE); - $entity->isDefaultRevision($default_revision); - - if ($entity instanceof EntityPublishedInterface) { - $entity->{$published_state ? 'setPublished' : 'setUnpublished'}(); - } - } - } - - /** - * Check if an entity's default revision and/or state needs adjusting. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity to check. - * @param bool $published_state - * Whether the state being transitioned to is a published state or not. - * - * @return bool - * TRUE when either the default revision or the state needs to be updated. - */ - protected function shouldModerate(ContentEntityInterface $entity, $published_state) { - // @todo clarify the first condition, https://www.drupal.org/node/2834953. - // First condition is needed so you can add a translation. - // Second condition checks to see if the published status has changed. - return $entity->isDefaultTranslation() || (!($entity instanceof EntityPublishedInterface) || $entity->isPublished() !== $published_state); - } - - /** - * {@inheritdoc} - */ public function onBundleModerationConfigurationFormSubmit(ConfigEntityInterface $bundle) { // The Revisions portion of Entity API is not uniformly applied or // consistent. Until that's fixed, we'll make a best-attempt to apply it to diff --git a/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php b/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php index c3d6ddd..64e7ae9 100644 --- a/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php +++ b/core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php @@ -16,18 +16,6 @@ interface ModerationHandlerInterface { /** - * Operates on moderated content entities preSave(). - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity to modify. - * @param bool $default_revision - * Whether the new revision should be made the default revision. - * @param bool $published_state - * Whether the state being transitioned to is a published state or not. - */ - public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state); - - /** * Operates on the bundle definition that has been marked as moderated. * * Note: The values on the EntityModerationForm itself are already saved diff --git a/core/modules/content_moderation/src/EntityOperations.php b/core/modules/content_moderation/src/EntityOperations.php index b4d637f..0962fbd 100644 --- a/core/modules/content_moderation/src/EntityOperations.php +++ b/core/modules/content_moderation/src/EntityOperations.php @@ -6,6 +6,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormBuilderInterface; @@ -96,6 +97,7 @@ public static function create(ContainerInterface $container) { * The entity being saved. */ public function entityPresave(EntityInterface $entity) { + /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ if (!$this->moderationInfo->isModeratedEntity($entity)) { return; } @@ -111,8 +113,15 @@ public function entityPresave(EntityInterface $entity) { || $current_state->isDefaultRevisionState() || !$this->isDefaultRevisionPublished($entity, $workflow); - // Fire per-entity-type logic for handling the save process. - $this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->onPresave($entity, $update_default_revision, $current_state->isPublishedState()); + if ($entity->isDefaultTranslation() || (!($entity instanceof EntityPublishedInterface) || $entity->isPublished() !== $current_state->isPublishedState())) { + // This is probably not necessary if configuration is setup correctly. + $entity->setNewRevision(TRUE); + $entity->isDefaultRevision($update_default_revision); + + if ($entity instanceof EntityPublishedInterface) { + $entity->{$current_state->isPublishedState() ? 'setPublished' : 'setUnpublished'}(); + } + } } } diff --git a/core/modules/system/tests/modules/entity_test/config/schema/entity_test.schema.yml b/core/modules/system/tests/modules/entity_test/config/schema/entity_test.schema.yml index bb84c24..d34d949 100644 --- a/core/modules/system/tests/modules/entity_test/config/schema/entity_test.schema.yml +++ b/core/modules/system/tests/modules/entity_test/config/schema/entity_test.schema.yml @@ -27,17 +27,3 @@ entity_test.entity_test_bundle.*: description: type: text label: 'Description' - -entity_test.entity_test_publish_bundle.*: - type: config_entity - label: 'Publishale entity test bundle' - mapping: - label: - type: label - label: 'Label' - id: - type: string - label: 'Machine-readable name' - description: - type: text - label: 'Description'