Problem/Motivation

1. Create a node, e.g. Article, with some sample content.
2. Wait a minute or so.
3. View node on public site (front page or /node/x), use quick-edit to alter one of the fields (e.g. title or description), then click Save.
4. View /node/x/revisions.

Expected behaviour:
1. on /node/x/revisions, time of current revision will be different from previous revisions (i.e. at least a minute later.)
2. because in DB, node_revision.revision_timestamp of latest revision should be different.

Actual behaviour:
revision_timestamp identical to previous revision

Proposed resolution

Write revision_timestamp property using current time.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#3 timestamp_duplicated-2823604-3.patch722 byteswturrell

Comments

wturrell created an issue. See original summary.

wturrell’s picture

Assigned: Unassigned » wturrell

Working on a patch for this.

wturrell’s picture

Status: Active » Needs review
StatusFileSize
new722 bytes
wturrell’s picture

Assigned: wturrell » Unassigned
wturrell’s picture

Title: Timestamp duplicated (not updated) after quick editing of node » Update timestamp correctly after quick edits (was being duplicated)
Issue summary: View changes

Use the issue template and update the issue title for a better commit message (resolution rather than problem.)

wturrell’s picture

Note: This bug is present in 8.3.x too (I'm not entirely clear how to tag an issue when that's the case, or which is the correct branch to work on. Feel free to point me towards suitable docs.)

wim leers’s picture

Issue tags: +Needs tests

Thanks for all your help! Much appreciated :)

See

  /**
   * Initialize the form state and the entity before the first form build.
   */
  protected function init(FormStateInterface $form_state, EntityInterface $entity, $field_name) {
    // @todo Rather than special-casing $node->revision, invoke prepareEdit()
    //   once https://www.drupal.org/node/1863258 lands.
    if ($entity->getEntityTypeId() == 'node') {
      $node_type = $this->nodeTypeStorage->load($entity->bundle());
      $entity->setNewRevision($node_type->isNewRevision());
      $entity->revision_log = NULL;
    }
    …
  }

  …

  protected function buildEntity(array $form, FormStateInterface $form_state) {
    /** @var $entity \Drupal\Core\Entity\EntityInterface */
    $entity = clone $form_state->get('entity');
    $field_name = $form_state->get('field_name');

    $form_state->get('form_display')->extractFormValues($entity, $form, $form_state);

    // @todo Refine automated log messages and abstract them to all entity
    //   types: https://www.drupal.org/node/1678002.
    if ($entity->getEntityTypeId() == 'node' && $entity->isNewRevision() && $entity->revision_log->isEmpty()) {
      $entity->revision_log = t('Updated the %field-name field through in-place editing.', array('%field-name' => $entity->get($field_name)->getFieldDefinition()->getLabel()));
    }

    return $entity;
  }

i.e. that's all the revision handling we have today. We simply respect the entity type's "autocreate revisions or not" setting.

But I understand that the problem is that the revision timestamp is not being updated accordingly. I'd expect the Entity API to handle this for us. Where is revision_timestamp being set for regular node edits? (I couldn't find it in a quick search.)

wim leers’s picture

Title: Update timestamp correctly after quick edits (was being duplicated) » Set Node revision_timestamp to current time when quick editing (is identical to the last revision's timestamp))
Version: 8.2.1 » 8.2.x-dev
Status: Needs review » Postponed (maintainer needs more info)

Clarifying issue title further.

tstoeckler’s picture

Status: Postponed (maintainer needs more info) » Active

I'd expect the Entity API to handle this for us.

I think we all would. Unfortunately none of us live in that beatiful world you depict.

See \Drupal\node\NodeForm::submitForm(). There the setNewRevision() flag is being set and the revision author and timestamp, as well. (The revision log field comes from the form values.)

tstoeckler’s picture

I wasn't aware #1863258: Move entity preparation from form controller to entity class: "last changed" timestamp not updated and "create new revision" setting not respected when updating entities via Entity API existed, and that seems like super, super non-trivial to get done at this point, but yes, I think that is correct.

wim leers’s picture

Title: Set Node revision_timestamp to current time when quick editing (is identical to the last revision's timestamp)) » revision_timestamp is not set to current time when quick editing (it stays unchanged)

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.