You are here

public function Media::preSaveRevision in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::preSaveRevision()
  2. 9 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::preSaveRevision()

Acts on a revision before it gets saved.

Parameters

EntityStorageInterface $storage: The entity storage object.

object $record: The revision object.

Overrides ContentEntityBase::preSaveRevision

File

core/modules/media/src/Entity/Media.php, line 325

Class

Media
Defines the media entity class.

Namespace

Drupal\media\Entity

Code

public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
  parent::preSaveRevision($storage, $record);
  $is_new_revision = $this
    ->isNewRevision();
  if (!$is_new_revision && isset($this->original) && empty($record->revision_log_message)) {

    // If we are updating an existing media item without adding a
    // new revision, we need to make sure $entity->revision_log_message is
    // reset whenever it is empty.
    // Therefore, this code allows us to avoid clobbering an existing log
    // entry with an empty one.
    $record->revision_log_message = $this->original->revision_log_message->value;
  }
  if ($is_new_revision) {
    $record->revision_created = self::getRequestTime();
  }
}