You are here

public function FormComponentAddForm::ajaxSubmit in Flexiform 8

Ajax the plugin selection.

File

src/Form/FormComponentAddForm.php, line 185

Class

FormComponentAddForm
Provides a form for adding new form components.

Namespace

Drupal\flexiform\Form

Code

public function ajaxSubmit(array $form, FormStateInterface $form_state) {

  // Prepare redirect parameters.
  $params = [
    'form_mode_name' => $this->formDisplay
      ->get('mode'),
  ];
  $entity_type_id = $this->formDisplay
    ->get('targetEntityType');
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  if ($route_name = $entity_type
    ->get('field_ui_base_route')) {
    $route = $this->router
      ->getCollection()
      ->get($route_name);
    $path = $route
      ->getPath();
    if (strpos($path, '{' . $entity_type
      ->getBundleEntityType() . '}') !== FALSE) {
      $params[$entity_type
        ->getBundleEntityType()] = $this->formDisplay
        ->get('bundle');
    }
    elseif (strpos($path, '{bundle}') !== FALSE) {
      $params['bundles'] = $this->formDisplay
        ->get('bundle');
    }
  }
  $response = new AjaxResponse();
  $response
    ->addCommand(new CloseModalDialogCommand());
  $response
    ->addCommand(new RedirectCommand((new Url("entity.entity_form_display.{$entity_type_id}.form_mode", $params))
    ->toString()));
  return $response;
}