You are here

public function FormEntityBaseForm::ajaxSubmit in Flexiform 8

Ajax the plugin selection.

1 method overrides FormEntityBaseForm::ajaxSubmit()
FormEntityAddForm::ajaxSubmit in src/Form/FormEntityAddForm.php
Ajax the plugin selection.

File

src/Form/FormEntityBaseForm.php, line 213

Class

FormEntityBaseForm
Provides a base class for entity forms.

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;
}