summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-05-23 17:03:34 (GMT)
committerAlex Pott2017-05-23 17:03:34 (GMT)
commit3225473ddddf23fbfd9d22fe27190165a701c744 (patch)
treec5481180c647e17331b6beff2f70af823a73f9f3
parentcade2c61d15bace0a6b70c7986a5cc3349f1a71b (diff)
Issue #2865213 by acbramley, Sam152, timmillwood: Moderation form submission does not set revision author
-rw-r--r--core/modules/content_moderation/src/Form/EntityModerationForm.php6
-rw-r--r--core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php22
2 files changed, 27 insertions, 1 deletions
diff --git a/core/modules/content_moderation/src/Form/EntityModerationForm.php b/core/modules/content_moderation/src/Form/EntityModerationForm.php
index 6e4daea..ea2fedd 100644
--- a/core/modules/content_moderation/src/Form/EntityModerationForm.php
+++ b/core/modules/content_moderation/src/Form/EntityModerationForm.php
@@ -3,6 +3,7 @@
namespace Drupal\content_moderation\Form;
use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\content_moderation\ModerationInformationInterface;
@@ -127,8 +128,11 @@ class EntityModerationForm extends FormBase {
$new_state = $form_state->getValue('new_state');
$entity->set('moderation_state', $new_state);
- $entity->revision_log = $form_state->getValue('revision_log');
+ if ($entity instanceof RevisionLogInterface) {
+ $entity->setRevisionLogMessage($form_state->getValue('revision_log'));
+ $entity->setRevisionUserId($this->currentUser()->id());
+ }
$entity->save();
drupal_set_message($this->t('The moderation state has been updated.'));
diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
index c185e28..3882c764 100644
--- a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
@@ -183,4 +183,26 @@ class ModerationFormTest extends ModerationStateTestBase {
$this->assertResponse(403);
}
+ /**
+ * Tests the revision author is updated when the moderation form is used.
+ */
+ public function testModerationFormSetsRevisionAuthor() {
+ // Create new moderated content in published.
+ $node = $this->createNode(['type' => 'moderated_content', 'moderation_state' => 'published']);
+ // Make a forward revision.
+ $node->title = $this->randomMachineName();
+ $node->moderation_state->value = 'draft';
+ $node->save();
+
+ $another_user = $this->drupalCreateUser($this->permissions);
+ $this->grantUserPermissionToCreateContentOfType($another_user, 'moderated_content');
+ $this->drupalLogin($another_user);
+ $this->drupalPostForm(sprintf('node/%d/latest', $node->id()), [
+ 'new_state' => 'published',
+ ], t('Apply'));
+
+ $this->drupalGet(sprintf('node/%d/revisions', $node->id()));
+ $this->assertText('by ' . $another_user->getAccountName());
+ }
+
}