You are here

protected function TaxonomyManagerForm::modalHelper in Taxonomy Manager 8

Same name and namespace in other branches
  1. 2.0.x src/Form/TaxonomyManagerForm.php \Drupal\taxonomy_manager\Form\TaxonomyManagerForm::modalHelper()

Helper function to generate a modal form within an AJAX callback.

Parameters

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

string $class_name: The class name of the form to embed in the modal.

string $route_name: The route name the form is located.

string $title: The modal title.

Return value

\Drupal\Core\Ajax\AjaxResponse The ajax response.

4 calls to TaxonomyManagerForm::modalHelper()
TaxonomyManagerForm::addFormCallback in src/Form/TaxonomyManagerForm.php
AJAX callback handler for add form.
TaxonomyManagerForm::deleteFormCallback in src/Form/TaxonomyManagerForm.php
AJAX callback handler for delete form.
TaxonomyManagerForm::exportFormCallback in src/Form/TaxonomyManagerForm.php
AJAX callback handler for export terms from a given vocabulary.
TaxonomyManagerForm::moveFormCallback in src/Form/TaxonomyManagerForm.php
AJAX callback handler for move form.

File

src/Form/TaxonomyManagerForm.php, line 358

Class

TaxonomyManagerForm
Taxonomy manager class.

Namespace

Drupal\taxonomy_manager\Form

Code

protected function modalHelper(FormStateInterface $form_state, $class_name, $route_name, $title) {
  $taxonomy_vocabulary = $form_state
    ->getValue('voc');
  $selected_terms = $form_state
    ->getValue([
    'taxonomy',
    'manager',
    'tree',
  ]);
  $del_form = $this->formBuilder
    ->getForm($class_name, $taxonomy_vocabulary, $selected_terms);
  $del_form['#attached']['library'][] = 'core/drupal.dialog.ajax';

  // Change the form action url form the current site to the add form.
  $del_form['#action'] = $this
    ->url($route_name, [
    'taxonomy_vocabulary' => $taxonomy_vocabulary
      ->id(),
  ]);
  $response = new AjaxResponse();
  $response
    ->addCommand(new OpenModalDialogCommand($title, $del_form, [
    'width' => '700',
  ]));
  return $response;
}