Unverified Commit dfe16bd3 authored by acbramley's avatar acbramley Committed by larowlan

Issue #2864883 by acbramley, fenstrat, drupal-son: Moderation form submission...

Issue #2864883 by acbramley, fenstrat, drupal-son: Moderation form submission does not set revision author
parent 8792137f
......@@ -5,6 +5,7 @@ namespace Drupal\workbench_moderation\Form;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\workbench_moderation\Entity\ModerationState;
......@@ -16,20 +17,36 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityModerationForm extends FormBase {
/**
* Moderation info service.
*
* @var \Drupal\workbench_moderation\ModerationInformationInterface
*/
protected $moderationInfo;
/**
* State transition validation service.
*
* @var \Drupal\workbench_moderation\StateTransitionValidation
*/
protected $validation;
/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* EntityModerationForm constructor.
*
* @param \Drupal\workbench_moderation\ModerationInformationInterface $moderation_info
* Moderation info service.
* @param \Drupal\workbench_moderation\StateTransitionValidation $validation
* State transition validation service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager service.
*/
public function __construct(ModerationInformationInterface $moderation_info, StateTransitionValidation $validation, EntityTypeManagerInterface $entity_type_manager) {
$this->moderationInfo = $moderation_info;
$this->validation = $validation;
......@@ -121,7 +138,10 @@ class EntityModerationForm extends FormBase {
$new_state = $form_state->getValue('new_state');
$entity->moderation_state->target_id = $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();
......
......@@ -18,7 +18,7 @@ class ModerationFormTest extends ModerationStateTestBase {
$this->createContentTypeFromUI('Moderated content', 'moderated_content', TRUE, [
'draft',
'needs_review',
'published'
'published',
], 'draft');
$this->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content');
}
......@@ -109,4 +109,25 @@ class ModerationFormTest extends ModerationStateTestBase {
$this->assertText('Needs Review', 'Correct status found on the latest-version page.');
}
/**
* 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->moderation_state->target_id = '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' => 'needs_review',
], 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