Commit 839d67fa authored by catch's avatar catch

Issue #2922018 by jhedstrom, amateescu: Set revision creation time when moderating content

parent 20564b99
......@@ -2,6 +2,7 @@
namespace Drupal\content_moderation\Form;
use Drupal\Component\Datetime\Time;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\Core\Form\FormBase;
......@@ -25,6 +26,13 @@ class EntityModerationForm extends FormBase {
*/
protected $moderationInfo;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\Time
*/
protected $time;
/**
* The moderation state transition validation service.
*
......@@ -39,9 +47,12 @@ class EntityModerationForm extends FormBase {
* The moderation information service.
* @param \Drupal\content_moderation\StateTransitionValidation $validation
* The moderation state transition validation service.
* @param \Drupal\Component\Datetime\Time $time
* The time service.
*/
public function __construct(ModerationInformationInterface $moderation_info, StateTransitionValidation $validation) {
public function __construct(ModerationInformationInterface $moderation_info, StateTransitionValidation $validation, Time $time) {
$this->moderationInfo = $moderation_info;
$this->time = $time;
$this->validation = $validation;
}
......@@ -51,7 +62,8 @@ public function __construct(ModerationInformationInterface $moderation_info, Sta
public static function create(ContainerInterface $container) {
return new static(
$container->get('content_moderation.moderation_information'),
$container->get('content_moderation.state_transition_validation')
$container->get('content_moderation.state_transition_validation'),
$container->get('datetime.time')
);
}
......@@ -132,6 +144,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$entity->set('moderation_state', $new_state);
if ($entity instanceof RevisionLogInterface) {
$entity->setRevisionCreationTime($this->time->getRequestTime());
$entity->setRevisionLogMessage($form_state->getValue('revision_log'));
$entity->setRevisionUserId($this->currentUser()->id());
}
......
......@@ -206,6 +206,7 @@ public function testModerationFormSetsRevisionAuthor() {
// Make a pending revision.
$node->title = $this->randomMachineName();
$node->moderation_state->value = 'draft';
$node->setRevisionCreationTime(12345);
$node->save();
$another_user = $this->drupalCreateUser($this->permissions);
......@@ -217,6 +218,10 @@ public function testModerationFormSetsRevisionAuthor() {
$this->drupalGet(sprintf('node/%d/revisions', $node->id()));
$this->assertText('by ' . $another_user->getAccountName());
// Verify the revision creation time has been updated.
$node = $node->load($node->id());
$this->assertGreaterThan(12345, $node->getRevisionCreationTime());
}
/**
......
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