function NodeForm::preview

Same name and namespace in other branches
  1. 9 core/modules/node/src/NodeForm.php \Drupal\node\NodeForm::preview()
  2. 8.9.x core/modules/node/src/NodeForm.php \Drupal\node\NodeForm::preview()
  3. 11.x core/modules/node/src/NodeForm.php \Drupal\node\NodeForm::preview()
  4. 11.x core/modules/node/src/Form/NodeForm.php \Drupal\node\Form\NodeForm::preview()

Form submission handler for the 'preview' action.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

core/modules/node/src/NodeForm.php, line 252

Class

NodeForm
Form handler for the node edit forms.

Namespace

Drupal\node

Code

public function preview(array $form, FormStateInterface $form_state) {
  $store = $this->tempStoreFactory
    ->get('node_preview');
  $this->entity->in_preview = TRUE;
  $store->set($this->entity
    ->uuid(), $form_state);
  $route_parameters = [
    'node_preview' => $this->entity
      ->uuid(),
    'view_mode_id' => 'full',
  ];
  $options = [];
  $query = $this->getRequest()->query;
  if ($query->has('destination')) {
    $options['query']['destination'] = $query->get('destination');
    $query->remove('destination');
  }
  $form_state->setRedirect('entity.node.preview', $route_parameters, $options);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.