diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module
index c672829ce5..ed5fa267e4 100644
--- a/core/modules/content_moderation/content_moderation.module
+++ b/core/modules/content_moderation/content_moderation.module
@@ -133,9 +133,9 @@ function content_moderation_entity_view(array &$build, EntityInterface $entity,
/**
* Implements hook_entity_access().
*
- * Nodes in particular should be viewable if unpublished and the user has
- * the appropriate permission. This permission is therefore effectively
- * mandatory for any user that wants to moderate things.
+ * Entities should be viewable if unpublished and the user has the appropriate
+ * permission. This permission is therefore effectively mandatory for any user
+ * that wants to moderate things.
*/
function content_moderation_entity_access(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\content_moderation\ModerationInformationInterface $moderation_info */
@@ -158,7 +158,7 @@ function content_moderation_entity_access(EntityInterface $entity, $operation, A
$access_result->addCacheableDependency($entity);
$access_result->addCacheableDependency($account);
- $workflow = \Drupal::service('content_moderation.moderation_information')->getWorkflowForEntity($entity);
+ $workflow = $moderation_info->getWorkflowForEntity($entity);
$access_result->addCacheableDependency($workflow);
foreach ($valid_transition_targets as $valid_transition_target) {
$access_result->addCacheableDependency($valid_transition_target);
diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php
index 3620c0abcd..90362abb38 100644
--- a/core/modules/content_moderation/src/EntityTypeInfo.php
+++ b/core/modules/content_moderation/src/EntityTypeInfo.php
@@ -314,8 +314,8 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id
else {
$type_label = $entity->getEntityType()->getLabel();
}
- $label = \Drupal::translation()->translate('Unable to save this @type_label.', ['@type_label' => $type_label]);
- $message = \Drupal::translation()->translate('Publish or delete the latest draft revision to allow all workflow transitions.', ['@latest_revision_edit_url' => $latest_revision->toUrl('edit-form', ['language' => $latest_revision->language()])->toString(), '@latest_revision_delete_url' => $latest_revision->toUrl('delete-form', ['language' => $latest_revision->language()])->toString()]);
+ $label = $this->t('Unable to save this @type_label.', ['@type_label' => $type_label]);
+ $message = $this->t('Publish or delete the latest draft revision to allow all workflow transitions.', ['@latest_revision_edit_url' => $latest_revision->toUrl('edit-form', ['language' => $latest_revision->language()])->toString(), '@latest_revision_delete_url' => $latest_revision->toUrl('delete-form', ['language' => $latest_revision->language()])->toString()]);
drupal_set_message(Markup::create($label . ' ' . $message), 'error');
$form['actions']['#access'] = FALSE;
@@ -347,23 +347,6 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id
}
/**
- * @param \Drupal\Core\Entity\EntityInterface $entity
- * @return \Drupal\Core\Entity\EntityInterface
- */
- protected function getTranslationAffectedRevision(EntityInterface $entity) {
- if ($entity->isRevisionTranslationAffected()) {
- return $entity;
- }
- /** @var \Drupal\Core\Language\LanguageInterface $language */
- foreach ($entity->getTranslationLanguages() as $language) {
- $translation = $entity->getTranslation($language->getId());
- if ($translation->isRevisionTranslationAffected()) {
- return $translation;
- }
- }
- }
-
- /**
* Redirect content entity edit forms on save, if there is a forward revision.
*
* When saving their changes, editors should see those changes displayed on
diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
index 5e5a64bc7b..61805768f7 100644
--- a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
@@ -11,7 +11,6 @@
*/
class ModerationFormTest extends ModerationStateTestBase {
-
/**
* Modules to enable.
*
@@ -201,10 +200,7 @@ public function testNonBundleModerationForm() {
*/
public function testModerationFormSetsRevisionAuthor() {
// Create new moderated content in published.
- $node = $this->createNode([
- 'type' => 'moderated_content',
- 'moderation_state' => 'published'
- ]);
+ $node = $this->createNode(['type' => 'moderated_content', 'moderation_state' => 'published']);
// Make a forward revision.
$node->title = $this->randomMachineName();
$node->moderation_state->value = 'draft';
@@ -256,6 +252,7 @@ public function testContentTranslationNodeForm() {
$this->assertTrue($node->language(), 'en');
$edit_path = sprintf('node/%d/edit', $node->id());
$translate_path = sprintf('node/%d/translations/add/en/fr', $node->id());
+ $french = \Drupal::languageManager()->getLanguage('fr');
// Add french translation (revision 2).
$this->drupalGet($translate_path);
@@ -267,7 +264,7 @@ public function testContentTranslationNodeForm() {
], t('Save and Publish (this translation)'));
// Add french forward revision (revision 3).
- $this->drupalGet('fr/' . $edit_path);
+ $this->drupalGet($edit_path, ['language' => $french]);
$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)"]'));
@@ -283,7 +280,7 @@ public function testContentTranslationNodeForm() {
$this->assertSession()->pageTextContains('Unable to save this Moderated content.');
// Publish the french forward revision (revision 4).
- $this->drupalGet('fr/' . $edit_path);
+ $this->drupalGet($edit_path, ['language' => $french]);
$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)"]'));
@@ -301,7 +298,7 @@ public function testContentTranslationNodeForm() {
], t('Save and Publish (this translation)'));
// Make sure we're allowed to create a forward french revision.
- $this->drupalGet('fr/' . $edit_path);
+ $this->drupalGet($edit_path, ['language' => $french]);
$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)"]'));
@@ -316,7 +313,7 @@ public function testContentTranslationNodeForm() {
], t('Save and Create New Draft (this translation)'));
// Make sure we're not allowed to create a forward french revision.
- $this->drupalGet('fr/' . $edit_path);
+ $this->drupalGet($edit_path, ['language' => $french]);
$this->assertFalse($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)"]'));
@@ -332,7 +329,7 @@ public function testContentTranslationNodeForm() {
], t('Save and Publish (this translation)'));
// Make sure we're allowed to create a forward french revision.
- $this->drupalGet('fr/' . $edit_path);
+ $this->drupalGet($edit_path, ['language' => $french]);
$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)"]'));
@@ -388,24 +385,32 @@ public function testContentTranslationNodeForm() {
$this->drupalPostForm(NULL, [], t('Save and Create New Draft (this translation)'));
// Add another draft for the translation (revision 3).
- $this->drupalGet('fr/' . $edit_path);
+ $this->drupalGet($edit_path, ['language' => $french]);
$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, [], t('Save and Create New Draft (this translation)'));
- // It should be possible to create a further draft.
- $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->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]'));
-
// Editing the original translation should not be possible.
$this->drupalGet($edit_path);
$this->assertFalse($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->assertSession()->pageTextContains('Unable to save this Moderated content.');
+
+ // Updating and publishing the french translation is still possible.
+ $this->drupalGet($edit_path, ['language' => $french]);
+ $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, [], t('Save and Publish (this translation)'));
+
+ // Now the french translation is published, an english draft can be added.
+ $this->drupalGet($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, [], t('Save and Create New Draft (this translation)'));
}
}
diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php
index 7b506136c2..8516e87871 100644
--- a/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php
@@ -150,6 +150,8 @@ public function testTranslateModeratedContent() {
$english_node = $this->drupalGetNodeByTitle('Another node', TRUE);
$french_node = $english_node->getTranslation('fr');
$this->assertEqual($french_node->moderation_state->value, 'published');
+ $this->assertTrue($french_node->isPublished());
+ $this->assertEqual($french_node->getTitle(), 'New draft of translated node', 'The draft has replaced the published revision.');
// Publish the English article before testing the archive transition.
$this->drupalPostForm('node/' . $english_node->id() . '/edit', [], t('Save and Publish (this translation)'));