Skip to content
Snippets Groups Projects
Commit 260f5f67 authored by catch's avatar catch
Browse files

Issue #2868429 by Sam152, timmillwood, Adita, RaisinBranCrunch, catch:...

Issue #2868429 by Sam152, timmillwood, Adita, RaisinBranCrunch, catch: ModerationStateWidget depends on EntityTypeInterface::getBundleEntityType despite content moderation supporting entity types without a bundle
parent 83741b3a
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -110,7 +110,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ...@@ -110,7 +110,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
$entity = $items->getEntity(); $entity = $items->getEntity();
/* @var \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle_entity */ /* @var \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle_entity */
$bundle_entity = $this->entityTypeManager->getStorage($entity->getEntityType()->getBundleEntityType())->load($entity->bundle());
if (!$this->moderationInformation->isModeratedEntity($entity)) { if (!$this->moderationInformation->isModeratedEntity($entity)) {
// @todo https://www.drupal.org/node/2779933 write a test for this. // @todo https://www.drupal.org/node/2779933 write a test for this.
return $element + ['#access' => FALSE]; return $element + ['#access' => FALSE];
...@@ -118,9 +117,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ...@@ -118,9 +117,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
$workflow = $this->moderationInformation->getWorkflowForEntity($entity); $workflow = $this->moderationInformation->getWorkflowForEntity($entity);
$default = $items->get($delta)->value ? $workflow->getState($items->get($delta)->value) : $workflow->getTypePlugin()->getInitialState($workflow, $entity); $default = $items->get($delta)->value ? $workflow->getState($items->get($delta)->value) : $workflow->getTypePlugin()->getInitialState($workflow, $entity);
if (!$default) {
throw new \UnexpectedValueException(sprintf('The %s bundle has an invalid moderation state configuration, moderation states are enabled but no default is set.', $bundle_entity->label()));
}
/** @var \Drupal\workflows\Transition[] $transitions */ /** @var \Drupal\workflows\Transition[] $transitions */
$transitions = $this->validator->getValidTransitions($entity, $this->currentUser); $transitions = $this->validator->getValidTransitions($entity, $this->currentUser);
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Drupal\Tests\content_moderation\Functional; namespace Drupal\Tests\content_moderation\Functional;
use Drupal\workflows\Entity\Workflow;
/** /**
* Tests the moderation form, specifically on nodes. * Tests the moderation form, specifically on nodes.
* *
...@@ -115,4 +117,70 @@ public function testModerationForm() { ...@@ -115,4 +117,70 @@ public function testModerationForm() {
$this->assertResponse(403); $this->assertResponse(403);
} }
/**
* Test moderation non-bundle entity type.
*/
public function testNonBundleModerationForm() {
$this->drupalLogin($this->rootUser);
$workflow = Workflow::load('editorial');
$workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_mulrevpub', 'entity_test_mulrevpub');
$workflow->save();
// Create new moderated content in draft.
$this->drupalPostForm('entity_test_mulrevpub/add', [], t('Save and Create New Draft'));
// The latest version page should not show, because there is no forward
// revision.
$this->drupalGet('/entity_test_mulrevpub/manage/1/latest');
$this->assertResponse(403);
// Update the draft.
$this->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [], t('Save and Create New Draft'));
// The latest version page should not show, because there is still no
// forward revision.
$this->drupalGet('/entity_test_mulrevpub/manage/1/latest');
$this->assertResponse(403);
// Publish the draft.
$this->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [], t('Save and Publish'));
// The published view should not have a moderation form, because it is the
// default revision.
$this->drupalGet('entity_test_mulrevpub/manage/1');
$this->assertResponse(200);
$this->assertNoText('Status', 'The node view page has no moderation form.');
// The latest version page should not show, because there is still no
// forward revision.
$this->drupalGet('entity_test_mulrevpub/manage/1/latest');
$this->assertResponse(403);
// Make a forward revision.
$this->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [], t('Save and Create New Draft'));
// The published view should not have a moderation form, because it is the
// default revision.
$this->drupalGet('entity_test_mulrevpub/manage/1');
$this->assertResponse(200);
$this->assertNoText('Status', 'The node view page has no moderation form.');
// The latest version page should show the moderation form and have "Draft"
// status, because the forward revision is in "Draft".
$this->drupalGet('entity_test_mulrevpub/manage/1/latest');
$this->assertResponse(200);
$this->assertText('Status', 'Form text found on the latest-version page.');
$this->assertText('Draft', 'Correct status found on the latest-version page.');
// Submit the moderation form to change status to published.
$this->drupalPostForm('entity_test_mulrevpub/manage/1/latest', [
'new_state' => 'published',
], t('Apply'));
// The latest version page should not show, because there is no
// forward revision.
$this->drupalGet('entity_test_mulrevpub/manage/1/latest');
$this->assertResponse(403);
}
} }
...@@ -50,6 +50,7 @@ abstract class ModerationStateTestBase extends BrowserTestBase { ...@@ -50,6 +50,7 @@ abstract class ModerationStateTestBase extends BrowserTestBase {
'block', 'block',
'block_content', 'block_content',
'node', 'node',
'entity_test',
]; ];
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment