You are here

public function NodeForm::preview in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/node/src/NodeForm.php \Drupal\node\NodeForm::preview()

Form submission handler for the 'preview' action.

Parameters

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

$form_state: The current state of the form.

File

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

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);
}