Commit 1dd470fe authored by Juraj Chlebec's avatar Juraj Chlebec Committed by Bálint Csuthy
Browse files

Issue #3092638 by havran: Add missing revision_medata_keys, fix preSaveRevision method

parent 8d1d2b8a
Loading
Loading
Loading
Loading
+7 −2
Changes for src/Entity/Box.php: 7 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -75,6 +75,11 @@ use Drupal\user\UserInterface;
 *     "translation-revert" = "/box/{box}/revisions/{box_revision}/revert/{langcode}",
 *     "collection" = "/admin/content/box",
 *   },
 *   revision_metadata_keys = {
 *     "revision_user" = "revision_uid",
 *     "revision_created" = "revision_timestamp",
 *     "revision_log_message" = "revision_log"
 *   },
 *   bundle_entity_type = "box_type",
 *   field_ui_base_route = "entity.box_type.edit_form",
 *   permission_granularity = "bundle",
@@ -134,12 +139,12 @@ class Box extends EditorialContentEntityBase implements BoxInterface {
  public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
    parent::preSaveRevision($storage, $record);

    if (!$this->isNewRevision() && isset($this->original) && (!isset($record->revision_log) || $record->revision_log === '')) {
    if (!$this->isNewRevision() && isset($this->original) && (!isset($record->revision_log_message) || $record->revision_log_message === '')) {
      // If we are updating an existing box 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->revision_log->value;
      $record->revision_log_message = $this->original->revision_log_message->value;
    }
  }