本文整理汇总了PHP中Drupal\node\NodeInterface::setNewRevision方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeInterface::setNewRevision方法的具体用法?PHP NodeInterface::setNewRevision怎么用?PHP NodeInterface::setNewRevision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\NodeInterface
的用法示例。
在下文中一共展示了NodeInterface::setNewRevision方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createNodeRevision
/**
* Creates a new revision for a given node.
*
* @param \Drupal\node\NodeInterface $node
* A node object.
*
* @return \Drupal\node\NodeInterface
* A node object with up to date revision information.
*/
protected function createNodeRevision(NodeInterface $node)
{
// Create revision with a random title and body and update variables.
$node->title = $this->randomMachineName();
$node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format());
$node->setNewRevision();
$node->save();
return $node;
}
示例2: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state)
{
$this->revision->setNewRevision();
// Make this the new default revision for the node.
$this->revision->isDefaultRevision(TRUE);
// The revision timestamp will be updated when the revision is saved. Keep the
// original one for the confirmation message.
$original_revision_timestamp = $this->revision->getRevisionCreationTime();
$this->revision->revision_log = t('Copy of the revision from %date.', array('%date' => format_date($original_revision_timestamp)));
$this->revision->save();
watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()));
drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => format_date($original_revision_timestamp))));
$form_state['redirect_route'] = array('route_name' => 'node.revision_overview', 'route_parameters' => array('node' => $this->revision->id()));
}
示例3: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$this->revision->setNewRevision();
// Make this the new default revision for the node.
$this->revision->isDefaultRevision(TRUE);
// The revision timestamp will be updated when the revision is saved. Keep the
// original one for the confirmation message.
$original_revision_timestamp = $this->revision->getRevisionCreationTime();
$this->revision->revision_log = t('Copy of the revision from %date.', array('%date' => format_date($original_revision_timestamp)));
$this->revision->save();
$this->logger('content')->notice('@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()));
drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', array('@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => format_date($original_revision_timestamp))));
$form_state->setRedirect('entity.node.version_history', array('node' => $this->revision->id()));
}
示例4: createRevisions
/**
* Creates a series of revisions for the specified node.
*
* @param \Drupal\node\NodeInterface $node
* The node object.
* @param $count
* The number of revisions to be created.
*/
protected function createRevisions(NodeInterface $node, $count)
{
for ($i = 0; $i < $count; $i++) {
$node->title = $this->randomString();
$node->untranslatable_string_field->value = $this->randomString();
$node->setNewRevision(TRUE);
$node->save();
}
}
示例5: prepareRevertedRevision
/**
* Prepares a revision to be reverted.
*
* @param \Drupal\node\NodeInterface $revision
* The revision to be reverted.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\node\NodeInterface
* The prepared revision ready to be stored.
*/
protected function prepareRevertedRevision(NodeInterface $revision, FormStateInterface $form_state)
{
$revision->setNewRevision();
$revision->isDefaultRevision(TRUE);
return $revision;
}
示例6: createRevisions
/**
* Creates a series of revisions for the specified node.
*
* @param \Drupal\node\NodeInterface $node
* The node object.
* @param $count
* The number of revisions to be created.
*/
protected function createRevisions(NodeInterface $node, $count) {
for ($i = 0; $i < $count; $i++) {
$node->title = $this->randomString();
$node->body = [
'value' => $this->randomMachineName(32),
'format' => filter_default_format(),
];
$node->untranslatable_string_field->value = $this->randomString();
$node->setNewRevision(TRUE);
$node->save();
}
}
示例7: prepareRevertedRevision
/**
* Prepares a revision to be reverted.
*
* @param \Drupal\node\NodeInterface $revision
* The revision to be reverted.
*
* @return \Drupal\node\NodeInterface
* The prepared revision ready to be stored.
*/
protected function prepareRevertedRevision(NodeInterface $revision)
{
/** @var \Drupal\node\NodeInterface $default_revision */
$default_revision = $this->nodeStorage->load($revision->id());
// If the entity is translated, make sure only translations affected by the
// specified revision are reverted.
$languages = $default_revision->getTranslationLanguages();
if (count($languages) > 1) {
// @todo Instead of processing all the available translations, we should
// let the user decide which translations should be reverted. See
// https://www.drupal.org/node/2465907.
foreach ($languages as $langcode => $language) {
if ($revision->hasTranslation($langcode) && !$revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
$revision_translation = $revision->getTranslation($langcode);
$default_translation = $default_revision->getTranslation($langcode);
foreach ($default_revision->getFieldDefinitions() as $field_name => $definition) {
if ($definition->isTranslatable()) {
$revision_translation->set($field_name, $default_translation->get($field_name)->getValue());
}
}
}
}
}
$revision->setNewRevision();
$revision->isDefaultRevision(TRUE);
return $revision;
}