Esempio n. 1
0
  /**
   * Prepares a revision to be reverted.
   *
   * @param \Drupal\node\NodeInterface $revision
   *   The revision to be reverted.
   *   The type of $revision should be
   *   \Drupal\Core\Entity\ContentEntityInterface. But at the moment we need to
   *   stay compatible with
   *   \Drupal\node\Form\NodeRevisionRevertForm::prepareRevertedRevision(). See
   *   https://www.drupal.org/node/2350939
   * @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) {
    foreach ($revision->getFieldDefinitions() as $field_name => $definition) {
      if ($form_state->getValue('revert_' . $field_name)) {
        $this->latestRevision->set($field_name, $revision->get($field_name)->getValue());
      }
    }

    $this->latestRevision->setNewRevision();
    $this->latestRevision->isDefaultRevision(TRUE);

    return $this->latestRevision;
  }