Issue #2865213 by acbramley, Sam152, timmillwood: Moderation form submission does not set revision author
parent
cade2c61d1
commit
3225473ddd
|
|
@ -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.'));
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue