Problem/Motivation

This:

  public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
    parent::preSaveRevision($storage, $record);

…

    if ($is_new_revision) {
      $record->revision_created = self::getRequestTime();
    }
  }

… causes the Media entity type's revision timestamp to behave differently compared to all other entity types. Discovered while working on #2835767-45: Media + REST: comprehensive test coverage for Media + MediaType entity types.

i.e. it causes the value set by setRevisionCreationTime() to be overwritten.

Proposed resolution

Either do the same as Node, or update Node to the same as Media.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 2897026-4.patch4.03 KBseanb
#6 2897026-6.patch4.03 KBseanb
#6 interdiff-4-6.txt510 bytesseanb

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Title: \Drupal\media\Entity\Media::preSaveRevision() results in different behavior for the revision timestamp compared to other entity types » \Drupal\media\Entity\Media::preSaveRevision() handles the revision timestamp compared to other entity types
Issue tags: +Media Initiative
seanb’s picture

Just looked into this. This was changed in #2831274-59: Bring Media entity module to core as Media module to address the comment in 54.2. It looks like setRevisionCreationTime() is only called in ContentEntityForm.

Not exactly sure what the best way is to fix this. For media revisions created through the form the revision timestamp is changed as it should in ContentEntityForm. For new media the revision_created value is added by the default value of the created field type. When creating new revisions for existing media through code though, the revision timestamp never seems to be updated. It looks like this is also an issue for nodes.

I guess the solution would be to stop setting the revision timestamp in ContentEntityForm and always call setRevisionCreationTime() in preSaveRevision(). I don't think developers should need to set the revision timestamp. So in this case add the changes in media to node and block content as well.

seanb’s picture

Status: Active » Needs review
StatusFileSize
new4.03 KB

Let's see what the testbot thinks of this.

Status: Needs review » Needs work

The last submitted patch, 4: 2897026-4.patch, failed testing. View results

seanb’s picture

Status: Needs work » Needs review
StatusFileSize
new4.03 KB
new510 bytes

Now with the correct column name for nodes..

Status: Needs review » Needs work

The last submitted patch, 6: 2897026-6.patch, failed testing. View results

berdir’s picture

wim leers’s picture

+1!

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

vijaycs85’s picture

Status: Needs work » Closed (outdated)

Some of the changes here are already in media and moved some of them to #2869056: Automatically set revision user/log information/created time on entity revisions

seanb’s picture