diff --git a/core/modules/content_moderation/src/Form/EntityModerationForm.php b/core/modules/content_moderation/src/Form/EntityModerationForm.php index 6e4daea0a6cf..ea2fedd0103d 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 c185e283f8c5..3882c764f191 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()); + } + }