Commit 3225473d authored by alexpott's avatar alexpott

Issue #2865213 by acbramley, Sam152, timmillwood: Moderation form submission...

Issue #2865213 by acbramley, Sam152, timmillwood: Moderation form submission does not set revision author
parent cade2c61
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\content_moderation\Form; namespace Drupal\content_moderation\Form;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\content_moderation\ModerationInformationInterface; use Drupal\content_moderation\ModerationInformationInterface;
...@@ -127,8 +128,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ...@@ -127,8 +128,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$new_state = $form_state->getValue('new_state'); $new_state = $form_state->getValue('new_state');
$entity->set('moderation_state', $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(); $entity->save();
drupal_set_message($this->t('The moderation state has been updated.')); drupal_set_message($this->t('The moderation state has been updated.'));
......
...@@ -183,4 +183,26 @@ public function testNonBundleModerationForm() { ...@@ -183,4 +183,26 @@ public function testNonBundleModerationForm() {
$this->assertResponse(403); $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());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment