Issue #2922018 by jhedstrom, amateescu: Set revision creation time when moderating content
							parent
							
								
									20564b99a0
								
							
						
					
					
						commit
						839d67fa83
					
				| 
						 | 
				
			
			@ -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 @@ class EntityModerationForm extends FormBase {
 | 
			
		|||
  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 @@ class EntityModerationForm extends FormBase {
 | 
			
		|||
    $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 @@ class ModerationFormTest extends ModerationStateTestBase {
 | 
			
		|||
    // 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 @@ class ModerationFormTest extends ModerationStateTestBase {
 | 
			
		|||
 | 
			
		||||
    $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());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue