You are here

protected function TaxonomyManagerForm::modalHelper in Taxonomy Manager 2.0.x

Same name and namespace in other branches
  1. 8 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.

6 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::exportCsvFormCallback in src/Form/TaxonomyManagerForm.php
AJAX callback handler for export terms from a given vocabulary.
TaxonomyManagerForm::exportFormCallback in src/Form/TaxonomyManagerForm.php
AJAX callback handler for export terms from a given vocabulary.
TaxonomyManagerForm::exportListFormCallback in src/Form/TaxonomyManagerForm.php
AJAX callback handler for export terms from a given vocabulary.

... See full list

File

src/Form/TaxonomyManagerForm.php, line 420

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 current form.
  $del_form['#action'] = Url::fromRoute($route_name, [
    'taxonomy_vocabulary' => $taxonomy_vocabulary
      ->id(),
  ])
    ->toString();
  $response = new AjaxResponse();
  $response
    ->addCommand(new OpenModalDialogCommand($title, $del_form, [
    'width' => '700',
  ]));
  return $response;
}