You are here

public function ReferenceForm::preview in Bibliography & Citation 2.0.x

Same name and namespace in other branches
  1. 8 modules/bibcite_entity/src/Form/ReferenceForm.php \Drupal\bibcite_entity\Form\ReferenceForm::preview()

Custom preview submit handler for Reference.

Parameters

array $form: Nested array of form elements that comprise the form.

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

Throws

\Drupal\Core\TempStore\TempStoreException

File

modules/bibcite_entity/src/Form/ReferenceForm.php, line 91

Class

ReferenceForm
Form controller for Reference edit forms.

Namespace

Drupal\bibcite_entity\Form

Code

public function preview(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\Core\TempStore\PrivateTempStoreFactory $tempStoreFactory */
  $tempStoreFactory = \Drupal::getContainer()
    ->get('tempstore.private');
  $store = $tempStoreFactory
    ->get('bibcite_reference_preview');

  /** @var \Drupal\bibcite_entity\Entity\Reference $entity */
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $entity->inPreview = TRUE;
  $store
    ->set($entity
    ->uuid(), $form_state);
  $config = $this
    ->config('bibcite_entity.reference.settings');
  $route_parameters = [
    'bibcite_reference_preview' => $entity
      ->uuid(),
    'view_mode_id' => $config
      ->get('display_override.reference_page_view_mode'),
  ];
  $options = [];
  $query = \Drupal::requestStack()
    ->getCurrentRequest()->query;
  if ($query
    ->has('destination')) {
    $options['query']['destination'] = $query
      ->get('destination');
    $query
      ->remove('destination');
  }
  $form_state
    ->setRedirect('entity.bibcite_reference.preview', $route_parameters, $options);
}