You are here

public function OpignoAnswer::preSaveRevision in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Entity/OpignoAnswer.php \Drupal\opigno_module\Entity\OpignoAnswer::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

src/Entity/OpignoAnswer.php, line 235

Class

OpignoAnswer
Defines the Answer entity.

Namespace

Drupal\opigno_module\Entity

Code

public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
  parent::preSaveRevision($storage, $record);
  $revision_log_field_name = static::getRevisionMetadataKey($this
    ->getEntityType(), 'revision_log_message');
  $revision_created_field_name = static::getRevisionMetadataKey($this
    ->getEntityType(), 'revision_created');
  $new_revision = $this
    ->isNewRevision();
  if (!$new_revision && isset($this->original) && (!isset($record->{$revision_log_field_name}) || $record->{$revision_log_field_name} === '')) {
    $record->{$revision_log_field_name} = $this->original
      ->getRevisionLogMessage();
  }
  if ($new_revision && (!isset($record->{$revision_created_field_name}) || empty($record->{$revision_created_field_name}))) {
    $record->{$revision_created_field_name} = $record->id == $this
      ->id() ? $this
      ->getCreatedTime() : \Drupal::time()
      ->getRequestTime();
  }
}