本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityInterface::preSaveRevision方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityInterface::preSaveRevision方法的具体用法?PHP ContentEntityInterface::preSaveRevision怎么用?PHP ContentEntityInterface::preSaveRevision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\ContentEntityInterface
的用法示例。
在下文中一共展示了ContentEntityInterface::preSaveRevision方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveRevision
/**
* Saves an entity revision.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity object.
*
* @return int
* The revision id.
*/
protected function saveRevision(ContentEntityInterface $entity)
{
$record = $this->mapToStorageRecord($entity->getUntranslated(), $this->revisionTable);
$entity->preSaveRevision($this, $record);
if ($entity->isNewRevision()) {
$insert_id = $this->database->insert($this->revisionTable, array('return' => Database::RETURN_INSERT_ID))->fields((array) $record)->execute();
// Even if this is a new revision, the revision ID key might have been
// set in which case we should not override the provided revision ID.
if (!isset($record->{$this->revisionKey})) {
$record->{$this->revisionKey} = $insert_id;
}
if ($entity->isDefaultRevision()) {
$this->database->update($this->entityType->getBaseTable())->fields(array($this->revisionKey => $record->{$this->revisionKey}))->condition($this->idKey, $record->{$this->idKey})->execute();
}
} else {
$this->database->update($this->revisionTable)->fields((array) $record)->condition($this->revisionKey, $record->{$this->revisionKey})->execute();
}
// Make sure to update the new revision key for the entity.
$entity->{$this->revisionKey}->value = $record->{$this->revisionKey};
return $record->{$this->revisionKey};
}