preSaveRevision example

/** * {@inheritdoc} */
  public function getInstances() {
    return \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(['plugin' => 'block_content:' . $this->uuid()]);
  }

  /** * {@inheritdoc} */
  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 we are updating an existing block_content without adding a new       // revision and the user did not supply a revision log, keep the existing       // one.       $record->revision_log = $this->original->getRevisionLogMessage();
    }
  }

  /** * {@inheritdoc} */
$this->assertFalse($this->entity->isTranslatable());
  }

  /** * @covers ::preSaveRevision */
  public function testPreSaveRevision() {
    // This method is internal, so check for errors on calling it only.     $storage = $this->createMock('\Drupal\Core\Entity\EntityStorageInterface');
    $record = new \stdClass();
    // Our mocked entity->preSaveRevision() returns NULL, so assert that.     $this->assertNull($this->entity->preSaveRevision($storage$record));
  }

  /** * Data provider for the ::getTypedData() test. * * The following entity data definitions, the first two being derivatives of * the last definition, will be tested in order: * * 1. entity:$entity_type:$bundle * 2. entity:$entity_type * 3. entity * * @see \Drupal\Core\Entity\EntityBase::getTypedData() * @see \Drupal\Core\Entity\EntityBase::getTypedDataClass() * @see \Drupal\Core\Entity\Plugin\DataType\Deriver\EntityDeriver * * @return array * Array of arrays with the following elements: * - A bool whether to provide a bundle-specific definition. * - A bool whether to provide an entity type-specific definition. */
if ($translation->bundle->entity->thumbnailDownloadsAreQueued() && $translation->shouldUpdateThumbnail($is_new)) {
          \Drupal::queue('media_entity_thumbnail')->createItem(['id' => $translation->id()]);
        }
      }
    }
  }

  /** * {@inheritdoc} */
  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 ($this->revisionTable) {
          if ($full_save) {
            $entity->{$this->revisionKey} = $this->saveRevision($entity);
          }
          else {
            $record = $this->mapToStorageRecord($entity->getUntranslated()$this->revisionTable);
            // Remove the revision ID from the record to enable updates on SQL             // variants that prevent updating serial columns, for example,             // mssql.             unset($record->{$this->revisionKey});
            $entity->preSaveRevision($this$record);
            $this->database
              ->update($this->revisionTable)
              ->fields((array) $record)
              ->condition($this->revisionKey, $entity->getRevisionId())
              ->execute();
          }
        }
        if ($default_revision && $this->dataTable) {
          $this->saveToSharedTables($entity);
        }
        if ($this->revisionDataTable) {
          
// If no revision author has been set explicitly, make the node owner the     // revision author.     if (!$this->getRevisionUser()) {
      $this->setRevisionUserId($this->getOwnerId());
    }
  }

  /** * {@inheritdoc} */
  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 we are updating an existing node 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;
    }
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.