You are here

public function EntityReferenceTreeController::openSearchForm in Entity Reference Tree Widget 8

Same name and namespace in other branches
  1. 2.x src/Controller/EntityReferenceTreeController.php \Drupal\entity_reference_tree\Controller\EntityReferenceTreeController::openSearchForm()

Callback for opening the modal form.

1 string reference to 'EntityReferenceTreeController::openSearchForm'
entity_reference_tree.routing.yml in ./entity_reference_tree.routing.yml
entity_reference_tree.routing.yml

File

src/Controller/EntityReferenceTreeController.php, line 63

Class

EntityReferenceTreeController
EntityReferenceTreeController class.

Namespace

Drupal\entity_reference_tree\Controller

Code

public function openSearchForm(Request $request, string $field_edit_id, string $bundle, string $entity_type, string $theme, int $dots) {
  $response = new AjaxResponse();

  // Get the modal form using the form builder.
  $modal_form = $this->formBuilder
    ->getForm('Drupal\\entity_reference_tree\\Form\\SearchForm', $field_edit_id, $bundle, $entity_type, $theme, $dots);

  // Add an AJAX command to open a modal dialog with the form as the content.
  $response
    ->addCommand(new OpenModalDialogCommand($this
    ->t(ucfirst(str_replace('_', ' ', $entity_type)) . ' tree'), $modal_form, [
    'width' => '800',
  ]));
  return $response;
}