public function LibraryItem::preSaveRevision in Paragraphs 8
Acts on a revision before it gets saved.
Parameters
EntityStorageInterface $storage: The entity storage object.
object $record: The revision object.
Overrides ContentEntityBase::preSaveRevision
File
- modules/
paragraphs_library/ src/ Entity/ LibraryItem.php, line 222
Class
- LibraryItem
- Defines the LibraryItem entity.
Namespace
Drupal\paragraphs_library\EntityCode
public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
parent::preSaveRevision($storage, $record);
if (!$this
->isNewRevision() && isset($this->original) && (!isset($record->revision_log) || $record->revision_log === '')) {
$record->revision_log = $this->original->revision_log->value;
}
// @todo Remove when https://www.drupal.org/project/drupal/issues/2869056 is
// fixed.
$new_revision = $this
->isNewRevision();
if (!$new_revision && isset($this->original) && (!isset($record->revision_log) || $record->revision_log === '')) {
// If we are updating an existing library item without adding a new
// revision, we need to make sure $entity->revision_log 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 = $this->original
->getRevisionLogMessage();
}
if ($new_revision && (!isset($record->revision_created) || empty($record->revision_created))) {
$record->revision_created = \Drupal::time()
->getRequestTime();
}
}