You are here

public function FormComponentAddForm::submitForm in Flexiform 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormInterface::submitForm

File

src/Form/FormComponentAddForm.php, line 145

Class

FormComponentAddForm
Provides a form for adding new form components.

Namespace

Drupal\flexiform\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $name = $form_state
    ->getValue('name');
  $options = [
    'component_type' => $this->componentType
      ->getPluginId(),
    'region' => $form_state
      ->getValue('region'),
    'admin_label' => $form_state
      ->getValue('admin_label'),
  ];
  $this->componentType
    ->addComponentFormSubmit($form['options'], $form_state);
  if ($plugin_options = $form_state
    ->getValue('options')) {
    $options += $plugin_options;
  }
  $this->formDisplay
    ->setComponent($name, $options);
  $this->formDisplay
    ->save();
  $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
      ->getRouteCollection()
      ->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');
    }
  }
  $form_state
    ->setRedirect("entity.entity_form_display.{$entity_type_id}.form_mode", $params);
}