Commit 59e527c5 authored by catch's avatar catch

Issue #2811927 by timmillwood, alexpott: Disabling Content moderation on a...

Issue #2811927 by timmillwood, alexpott: Disabling Content moderation on a bundle, removes the ability to perform create content on that bundle
parent d1ddab50
......@@ -23,6 +23,10 @@ class ModerationStateFieldItemList extends EntityReferenceFieldItemList {
protected function getModerationState() {
$entity = $this->getEntity();
if (!\Drupal::service('content_moderation.moderation_information')->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle())) {
return NULL;
}
if ($entity->id() && $entity->getRevisionId()) {
$revisions = \Drupal::service('entity.query')->get('content_moderation_state')
->condition('content_entity_type_id', $entity->getEntityTypeId())
......
......@@ -47,6 +47,7 @@ public function testCreatingContent() {
}
$node = reset($nodes);
$this->assertEqual('draft', $node->moderation_state->target_id);
$path = 'node/' . $node->id() . '/edit';
// Set up published revision.
......@@ -55,6 +56,7 @@ public function testCreatingContent() {
/* @var \Drupal\node\NodeInterface $node */
$node = \Drupal::entityTypeManager()->getStorage('node')->load($node->id());
$this->assertTrue($node->isPublished());
$this->assertEqual('published', $node->moderation_state->target_id);
// Verify that the state field is not shown.
$this->assertNoText('Published');
......@@ -62,6 +64,31 @@ public function testCreatingContent() {
// Delete the node.
$this->drupalPostForm('node/' . $node->id() . '/delete', array(), t('Delete'));
$this->assertText(t('The Moderated content moderated content has been deleted.'));
$this->drupalGet('admin/structure/types/manage/moderated_content/moderation');
$this->assertFieldByName('enable_moderation_state');
$this->assertFieldChecked('edit-enable-moderation-state');
$this->drupalPostForm(NULL, ['enable_moderation_state' => FALSE], t('Save'));
$this->drupalGet('admin/structure/types/manage/moderated_content/moderation');
$this->assertFieldByName('enable_moderation_state');
$this->assertNoFieldChecked('edit-enable-moderation-state');
$this->drupalPostForm('node/add/moderated_content', [
'title[0][value]' => 'non-moderated content',
], t('Save and publish'));
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'title' => 'non-moderated content',
]);
if (!$nodes) {
$this->fail('Non-moderated test node was not saved correctly.');
return;
}
$node = reset($nodes);
$this->assertEqual(NULL, $node->moderation_state->target_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