/** * 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; }
/** * {@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())); }
/** * {@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())); }
/** * 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(); } }
/** * 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; }
/** * 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(); } }
/** * 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; }