You are here

public function FormEntityBaseForm::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

1 call to FormEntityBaseForm::submitForm()
FormEntityAddForm::submitForm in src/Form/FormEntityAddForm.php
Form submission handler.
1 method overrides FormEntityBaseForm::submitForm()
FormEntityAddForm::submitForm in src/Form/FormEntityAddForm.php
Form submission handler.

File

src/Form/FormEntityBaseForm.php, line 173

Class

FormEntityBaseForm
Provides a base class for entity forms.

Namespace

Drupal\flexiform\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_state = MultipleEntityFormState::createForForm($form, $form_state);
  $namespace = $form_state
    ->getValue('namespace');
  $configuration = [
    'label' => $form_state
      ->getValue('label'),
    'plugin' => $this->formEntity
      ->getPluginId(),
  ];
  $this->formEntity
    ->configurationFormSubmit($form['configuration'], $form_state);
  if ($plugin_conf = $form_state
    ->getValue('configuration')) {
    $configuration += $plugin_conf;
  }
  $this->formDisplay
    ->getFormEnhancer('multiple_entities')
    ->addFormEntityConfig($namespace, $configuration);
  $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);
}