diff --git a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php index 94f10e9..c981013 100644 --- a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php +++ b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php @@ -98,9 +98,7 @@ public function convert($value, $definition, $name, array $defaults) { $latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, ['operation' => 'entity_upcast']); } - if ($latest_revision->isRevisionTranslationAffected()) { - $entity = $latest_revision; - } + $entity = $latest_revision; } return $entity; diff --git a/core/modules/content_moderation/src/StateTransitionValidation.php b/core/modules/content_moderation/src/StateTransitionValidation.php index ed9fde3..88a2e36 100644 --- a/core/modules/content_moderation/src/StateTransitionValidation.php +++ b/core/modules/content_moderation/src/StateTransitionValidation.php @@ -44,7 +44,7 @@ public function getValidTransitions(ContentEntityInterface $entity, AccountInter return array_filter($current_state->getTransitions(), function(Transition $transition) use ($workflow, $user, $entity) { return $user->hasPermission('use ' . $workflow->id() . ' transition ' . $transition->id()) - && !(!$transition->to()->isDefaultRevisionState() && $entity->isDefaultRevision() && $this->moderationInfo->hasForwardRevision($entity)); + && !($this->moderationInfo->hasForwardRevision($entity) && !(($entity->isDefaultRevision() && $transition->to()->isDefaultRevisionState()) || (!$entity->isDefaultRevision() && !$transition->to()->isDefaultRevisionState()))); }); } diff --git a/core/modules/content_moderation/src/Tests/ModerationFormTest.php b/core/modules/content_moderation/src/Tests/ModerationFormTest.php index 16da4e4..9e72da2 100644 --- a/core/modules/content_moderation/src/Tests/ModerationFormTest.php +++ b/core/modules/content_moderation/src/Tests/ModerationFormTest.php @@ -9,6 +9,19 @@ */ class ModerationFormTest extends ModerationStateTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = [ + 'node', + 'content_moderation', + 'locale', + 'content_translation', + ]; + /** * {@inheritdoc} */ @@ -103,4 +116,67 @@ public function testModerationForm() { $this->assertResponse(403); } + public function testContentTranslationNodeForm() { + $this->drupalLogin($this->rootUser); + + // Add French language. + $edit = [ + 'predefined_langcode' => 'fr', + ]; + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + + // Enable content translation on articles. + $this->drupalGet('admin/config/regional/content-language'); + $edit = [ + 'entity_types[node]' => TRUE, + 'settings[node][moderated_content][translatable]' => TRUE, + 'settings[node][moderated_content][settings][language][language_alterable]' => TRUE, + ]; + $this->drupalPostForm(NULL, $edit, t('Save configuration')); + + // Adding languages requires a container rebuild in the test running + // environment so that multilingual services are used. + $this->rebuildContainer(); + + // Create new moderated content in draft. + $this->drupalPostForm('node/add/moderated_content', [ + 'title[0][value]' => 'Some moderated content', + 'body[0][value]' => 'First version of the content.', + ], t('Save and Create New Draft')); + + $node = $this->drupalGetNodeByTitle('Some moderated content'); + $this->assertTrue($node->language(), 'en'); + $edit_path = sprintf('node/%d/edit', $node->id()); + $translate_path = sprintf('node/%d/translations/add/en/fr', $node->id()); + + // Add french translation. + $this->drupalGet($translate_path); + $this->assertTrue($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); + $this->assertTrue($this->xpath('//input[@value="Save and Publish (this translation)"]')); + $this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]')); + $this->drupalPostForm(NULL, [ + 'body[0][value]' => 'Second version of the content.', + ], t('Save and Publish (this translation)')); + + // Add french forward revision. + $this->drupalGet('fr/' . $edit_path); + $this->assertTrue($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); + $this->assertTrue($this->xpath('//input[@value="Save and Publish (this translation)"]')); + $this->assertTrue($this->xpath('//input[@value="Save and Archive (this translation)"]')); + $this->drupalPostForm(NULL, [ + 'body[0][value]' => 'Third version of the content.', + ], t('Save and Create New Draft (this translation)')); + + // Add another english revision. + $this->drupalGet($edit_path); + $this->assertTrue($this->xpath('//input[@value="Save and Create New Draft (this translation)"]')); + $this->assertFalse($this->xpath('//input[@value="Save and Publish (this translation)"]')); + $this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]')); + $this->drupalPostForm(NULL, [ + 'body[0][value]' => 'Forth version of the content.', + ], t('Save and Create New Draft (this translation)')); + + + } + }