diff --git a/config/install/workbench_moderation.moderation_state_transition.draft_draft.yml b/config/install/workbench_moderation.moderation_state_transition.draft_draft.yml index 4d9625c..63bcb56 100644 --- a/config/install/workbench_moderation.moderation_state_transition.draft_draft.yml +++ b/config/install/workbench_moderation.moderation_state_transition.draft_draft.yml @@ -4,6 +4,6 @@ dependencies: config: - workbench_moderation.moderation_state.draft id: draft_draft -label: 'Create new Draft' +label: 'Create New Draft' stateFrom: draft stateTo: draft diff --git a/src/StateTransitionValidation.php b/src/StateTransitionValidation.php index be32cd8..06ebe9a 100644 --- a/src/StateTransitionValidation.php +++ b/src/StateTransitionValidation.php @@ -136,12 +136,14 @@ class StateTransitionValidation { * @return ModerationStateTransition[] */ public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user) { - $current_state_id = $entity->moderation_state->entity->id(); + $bundle = $this->loadBundleEntity($entity->getEntityType()->getBundleEntityType(), $entity->bundle()); + + /** @var ModerationState $current_state */ + $current_state = $entity->moderation_state->entity; + $current_state_id = $current_state ? $current_state->id(): $bundle->getThirdPartySetting('workbench_moderation', 'default_moderation_state'); // Determine the states that are legal on this bundle. - $legal_bundle_states = $this - ->loadBundleEntity($entity->getEntityType()->getBundleEntityType(), $entity->bundle()) - ->getThirdPartySetting('workbench_moderation', 'allowed_moderation_states', []); + $legal_bundle_states = $bundle->getThirdPartySetting('workbench_moderation', 'allowed_moderation_states', []); // Legal transitions include those that are possible from the current state, // filtered by those whose target is legal on this bundle and that the diff --git a/src/Tests/ModerationFormTest.php b/src/Tests/ModerationFormTest.php index 7892d2e..243d990 100644 --- a/src/Tests/ModerationFormTest.php +++ b/src/Tests/ModerationFormTest.php @@ -53,7 +53,7 @@ class ModerationFormTest extends ModerationStateTestBase { // Make a new forward revision; after saving, the tab and form should show. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Second version of the content.', - ], t('Save and transition to Needs Review')); + ], t('Save and Request Review')); $this->drupalGet($latest_version_path); $this->assertResponse(200); $this->assertText('Second version of the content.'); @@ -64,7 +64,7 @@ class ModerationFormTest extends ModerationStateTestBase { // be unavailable and the public node page should have no form on it. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Third version of the content.', - ], t('Save and transition to Published')); + ], t('Save and Publish')); $this->drupalGet($canonical_path); $this->assertResponse(200); $this->assertNoText('Current status', 'The node view page has no moderation form.'); @@ -75,7 +75,7 @@ class ModerationFormTest extends ModerationStateTestBase { // be back, and have a form, while the node view page still has no form. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Fourth version of the content.', - ], t('Save and create new revision in Draft')); + ], t('Save and Create New Draft')); $this->drupalGet($latest_version_path); $this->assertResponse(200); $this->assertText('Current status', 'Form text found on the latest-version page.'); diff --git a/src/Tests/ModerationStateNodeTest.php b/src/Tests/ModerationStateNodeTest.php index 9c44e1b..e8caecf 100644 --- a/src/Tests/ModerationStateNodeTest.php +++ b/src/Tests/ModerationStateNodeTest.php @@ -52,9 +52,9 @@ class ModerationStateNodeTest extends ModerationStateTestBase { $path = 'node/' . $node->id() . '/edit'; // Set up needs review revision. - $this->drupalPostForm($path, [], t('Save and transition to Needs Review')); + $this->drupalPostForm($path, [], t('Save and Request Review')); // Set up published revision. - $this->drupalPostForm($path, [], t('Save and transition to Published')); + $this->drupalPostForm($path, [], t('Save and Publish')); \Drupal::entityTypeManager()->getStorage('node')->resetCache([$node->id()]); /* @var \Drupal\node\NodeInterface $node */ $node = \Drupal::entityTypeManager()->getStorage('node')->load($node->id()); @@ -86,7 +86,7 @@ class ModerationStateNodeTest extends ModerationStateTestBase { // version" tab. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Second version of the content.', - ], t('Save and transition to Needs Review')); + ], t('Save and Request Review')); $this->assertUrl(Url::fromRoute('entity.node.latest_version', ['node' => $node->id()])); $this->assertText('Second version of the content.'); @@ -94,7 +94,7 @@ class ModerationStateNodeTest extends ModerationStateTestBase { // canonical URL. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Third version of the content.', - ], t('Save and transition to Published')); + ], t('Save and Publish')); $this->assertUrl(Url::fromRoute('entity.node.canonical', ['node' => $node->id()])); $this->assertText('Third version of the content.'); @@ -102,7 +102,7 @@ class ModerationStateNodeTest extends ModerationStateTestBase { // "Latest version" tab. $this->drupalPostForm($edit_path, [ 'body[0][value]' => 'Fourth version of the content.', - ], t('Save and create new revision in Draft')); + ], t('Save and Create New Draft')); $this->assertUrl(Url::fromRoute('entity.node.latest_version', ['node' => $node->id()])); $this->assertText('Fourth version of the content.'); } diff --git a/src/Tests/ModerationStateNodeTypeTest.php b/src/Tests/ModerationStateNodeTypeTest.php index 8331108..a41cac2 100644 --- a/src/Tests/ModerationStateNodeTypeTest.php +++ b/src/Tests/ModerationStateNodeTypeTest.php @@ -69,7 +69,7 @@ class ModerationStateNodeTypeTest extends ModerationStateTestBase { $this->assertLinkByHref('node/' . $node->id() . '/edit'); $this->drupalGet('node/' . $node->id() . '/edit'); $this->assertResponse(200); - $this->assertRaw('Save as Draft'); + $this->assertRaw('Save and Create New Draft'); $this->assertNoRaw('Save and publish'); } diff --git a/src/Tests/ModerationStateTestBase.php b/src/Tests/ModerationStateTestBase.php index a4a3ef6..89a127f 100644 --- a/src/Tests/ModerationStateTestBase.php +++ b/src/Tests/ModerationStateTestBase.php @@ -35,6 +35,7 @@ abstract class ModerationStateTestBase extends WebTestBase { protected $permissions = [ 'administer moderation states', 'administer moderation state transitions', + 'use draft_draft transition', 'use draft_needs_review transition', 'use published_draft transition', 'use needs_review_published transition', diff --git a/src/Tests/NodeAccessTest.php b/src/Tests/NodeAccessTest.php index b03f573..a7a52fb 100644 --- a/src/Tests/NodeAccessTest.php +++ b/src/Tests/NodeAccessTest.php @@ -35,10 +35,12 @@ class NodeAccessTest extends ModerationStateTestBase { * Verifies that a non-admin user can still access the appropriate pages. */ public function testPageAccess() { + $this->drupalLogin($this->adminUser); + // Create a node to test with. $this->drupalPostForm('node/add/moderated_content', [ 'title[0][value]' => 'moderated content', - ], t('Save as Draft')); + ], t('Save and Create New Draft')); $nodes = \Drupal::entityTypeManager() ->getStorage('node') ->loadByProperties([ @@ -58,10 +60,11 @@ class NodeAccessTest extends ModerationStateTestBase { $latest_path = 'node/' . $node->id() . '/latest'; // Set up needs review revision. - $this->drupalPostForm($edit_path, [], t('Save and transition to Needs Review')); + $this->drupalPostForm($edit_path, [], t('Save and Request Review')); // Now make a new user and verify that the new user's access is correct. $user = $this->createUser([ + 'use draft_draft transition', 'use draft_needs_review transition', 'use published_draft transition', 'use needs_review_published transition', diff --git a/workbench_moderation.permissions.yml b/workbench_moderation.permissions.yml index b204a1b..88e1642 100644 --- a/workbench_moderation.permissions.yml +++ b/workbench_moderation.permissions.yml @@ -1,5 +1,5 @@ view any unpublished content: - title: View all unpublished content + title: View any unpublished content description: This permission is necessary for any users that may moderate content. 'administer moderation states':