Unverified Commit 09fe2d3e authored by alexpott's avatar alexpott

Issue #2946750 by Sam152, merauluka, timmillwood, catch: Node revisions forced...

Issue #2946750 by Sam152, merauluka, timmillwood, catch: Node revisions forced even if bundle not under moderation workflow

(cherry picked from commit 561de9989a0f85c34cc54f35645aca4e6d5708bc)
parent 483d35f3
...@@ -321,37 +321,36 @@ public function entityPrepareForm(EntityInterface $entity, $operation, FormState ...@@ -321,37 +321,36 @@ public function entityPrepareForm(EntityInterface $entity, $operation, FormState
public function formAlter(array &$form, FormStateInterface $form_state, $form_id) { public function formAlter(array &$form, FormStateInterface $form_state, $form_id) {
$form_object = $form_state->getFormObject(); $form_object = $form_state->getFormObject();
if ($form_object instanceof BundleEntityFormBase) { if ($form_object instanceof BundleEntityFormBase) {
$config_entity_type = $form_object->getEntity()->getEntityType(); $config_entity = $form_object->getEntity();
$bundle_of = $config_entity_type->getBundleOf(); $bundle_of = $config_entity->getEntityType()->getBundleOf();
if ($bundle_of if ($bundle_of
&& ($bundle_of_entity_type = $this->entityTypeManager->getDefinition($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->id())) {
$this->entityTypeManager->getHandler($config_entity_type->getBundleOf(), 'moderation')->enforceRevisionsBundleFormAlter($form, $form_state, $form_id); $this->entityTypeManager->getHandler($bundle_of, 'moderation')->enforceRevisionsBundleFormAlter($form, $form_state, $form_id);
} }
} }
elseif ($this->isModeratedEntityEditForm($form_object)) { elseif ($this->isModeratedEntityEditForm($form_object)) {
/** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */ /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $form_object->getEntity(); $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']) && in_array($form_object->getOperation(), ['edit', 'default'], TRUE)) {
$form['moderation_state']['#group'] = 'footer';
}
// If the publishing status exists in the meta region, replace it with $this->entityTypeManager
// the current state instead. ->getHandler($entity->getEntityTypeId(), 'moderation')
if (isset($form['meta']['published'])) { ->enforceRevisionsEntityFormAlter($form, $form_state, $form_id);
$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']) && in_array($form_object->getOperation(), ['edit', 'default'], TRUE)) {
$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();
} }
} }
} }
......
...@@ -67,9 +67,18 @@ public function testEnablingOnExistingContent() { ...@@ -67,9 +67,18 @@ public function testEnablingOnExistingContent() {
], t('Save')); ], t('Save'));
$this->assertText('Not moderated Test has been created.'); $this->assertText('Not moderated Test has been created.');
// Check that the 'Create new revision' is not disabled.
$this->drupalGet('/admin/structure/types/manage/not_moderated');
$this->assertNull($this->assertSession()->fieldExists('options[revision]')->getAttribute('disabled'));
// Now enable moderation state. // Now enable moderation state.
$this->enableModerationThroughUi('not_moderated'); $this->enableModerationThroughUi('not_moderated');
// Check that the 'Create new revision' checkbox is checked and disabled.
$this->drupalGet('/admin/structure/types/manage/not_moderated');
$this->assertSession()->checkboxChecked('options[revision]');
$this->assertSession()->fieldDisabled('options[revision]');
// And make sure it works. // And make sure it works.
$nodes = \Drupal::entityTypeManager()->getStorage('node') $nodes = \Drupal::entityTypeManager()->getStorage('node')
->loadByProperties(['title' => 'Test']); ->loadByProperties(['title' => 'Test']);
......
...@@ -112,10 +112,6 @@ protected function createContentTypeFromUi($content_type_name, $content_type_id, ...@@ -112,10 +112,6 @@ protected function createContentTypeFromUi($content_type_name, $content_type_id,
$this->drupalGet('admin/structure/types'); $this->drupalGet('admin/structure/types');
$this->clickLink('Add content type'); $this->clickLink('Add content type');
// Check that the 'Create new revision' checkbox is checked and disabled.
$this->assertSession()->checkboxChecked('options[revision]');
$this->assertSession()->fieldDisabled('options[revision]');
$edit = [ $edit = [
'name' => $content_type_name, 'name' => $content_type_name,
'type' => $content_type_id, 'type' => $content_type_id,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment