diff --git a/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php index b8911134cb..87e1b22c8d 100644 --- a/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php +++ b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php @@ -14,13 +14,6 @@ */ class NodeModerationHandler extends ModerationHandler { - /** - * The entity type definition. - * - * @var \Drupal\Core\Entity\EntityTypeInterface - */ - protected $entityType; - /** * The moderation information service. * @@ -31,13 +24,10 @@ class NodeModerationHandler extends ModerationHandler { /** * NodeModerationHandler constructor. * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_info * The moderation information service. */ - public function __construct(EntityTypeInterface $entity_type, ModerationInformationInterface $moderation_info) { - $this->entityType = $entity_type; + public function __construct(ModerationInformationInterface $moderation_info) { $this->moderationInfo = $moderation_info; } @@ -46,7 +36,6 @@ public function __construct(EntityTypeInterface $entity_type, ModerationInformat */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( - $entity_type, $container->get('content_moderation.moderation_information') ); } @@ -55,30 +44,18 @@ public static function createInstance(ContainerInterface $container, EntityTypeI * {@inheritdoc} */ public function enforceRevisionsEntityFormAlter(array &$form, FormStateInterface $form_state, $form_id) { - // Load the node definition and bundle name in order to verify that the - // current node type is assigned a content moderation workflow. If so then - // force the revisions checkbox to be checked and disabled. - $entity_form = $form_state->getStorage()['form_display']; - $bundle = $entity_form->getTargetBundle(); - if ($this->moderationInfo->shouldModerateEntitiesOfBundle($this->entityType, $bundle)) { - $form['revision']['#disabled'] = TRUE; - $form['revision']['#default_value'] = TRUE; - $form['revision']['#description'] = $this->t('Revisions are required.'); - } + $form['revision']['#disabled'] = TRUE; + $form['revision']['#default_value'] = TRUE; + $form['revision']['#description'] = $this->t('Revisions are required.'); } /** * {@inheritdoc} */ public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id) { - // Load the node definition and bundle name in order to verify that the - // current node type is assigned a content moderation workflow. If so then - // force the revisions checkbox to be checked and disabled. - $bundle = $form['type']['#default_value']; - if ($this->moderationInfo->shouldModerateEntitiesOfBundle($this->entityType, $bundle)) { - $form['workflow']['options']['#value']['revision'] = 'revision'; - $form['workflow']['options']['revision']['#disabled'] = TRUE; - } + // Force the revision checkbox on. + $form['workflow']['options']['#value']['revision'] = 'revision'; + $form['workflow']['options']['revision']['#disabled'] = TRUE; } } diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php index f54943d427..1c96b125c8 100644 --- a/core/modules/content_moderation/src/EntityTypeInfo.php +++ b/core/modules/content_moderation/src/EntityTypeInfo.php @@ -322,7 +322,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id $bundle_of = $config_entity_type->getBundleOf(); if ($bundle_of && ($bundle_of_entity_type = $this->entityTypeManager->getDefinition($bundle_of)) - && $this->moderationInfo->canModerateEntitiesOfEntityType($bundle_of_entity_type)) { + && $this->moderationInfo->shouldModerateEntitiesOfBundle($bundle_of_entity_type, $config_entity_type->id())) { $this->entityTypeManager->getHandler($config_entity_type->getBundleOf(), 'moderation')->enforceRevisionsBundleFormAlter($form, $form_state, $form_id); } } @@ -330,25 +330,23 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */ /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $form_object->getEntity(); - if ($this->moderationInfo->isModeratedEntity($entity)) { - $this->entityTypeManager - ->getHandler($entity->getEntityTypeId(), 'moderation') - ->enforceRevisionsEntityFormAlter($form, $form_state, $form_id); - - // Submit handler to redirect to the latest version, if available. - $form['actions']['submit']['#submit'][] = [EntityTypeInfo::class, 'bundleFormRedirect']; - - // Move the 'moderation_state' field widget to the footer region, if - // available. - if (isset($form['footer'])) { - $form['moderation_state']['#group'] = 'footer'; - } + $this->entityTypeManager + ->getHandler($entity->getEntityTypeId(), 'moderation') + ->enforceRevisionsEntityFormAlter($form, $form_state, $form_id); - // If the publishing status exists in the meta region, replace it with - // the current state instead. - if (isset($form['meta']['published'])) { - $form['meta']['published']['#markup'] = $this->moderationInfo->getWorkflowForEntity($entity)->getTypePlugin()->getState($entity->moderation_state->value)->label(); - } + // Submit handler to redirect to the latest version, if available. + $form['actions']['submit']['#submit'][] = [EntityTypeInfo::class, 'bundleFormRedirect']; + + // Move the 'moderation_state' field widget to the footer region, if + // available. + if (isset($form['footer'])) { + $form['moderation_state']['#group'] = 'footer'; + } + + // If the publishing status exists in the meta region, replace it with + // the current state instead. + if (isset($form['meta']['published'])) { + $form['meta']['published']['#markup'] = $this->moderationInfo->getWorkflowForEntity($entity)->getTypePlugin()->getState($entity->moderation_state->value)->label(); } } }