You are here

public function EntityUsageSettingsForm::submitForm in Entity Usage 8

Same name and namespace in other branches
  1. 8.4 src/Form/EntityUsageSettingsForm.php \Drupal\entity_usage\Form\EntityUsageSettingsForm::submitForm()
  2. 8.2 src/Form/EntityUsageSettingsForm.php \Drupal\entity_usage\Form\EntityUsageSettingsForm::submitForm()
  3. 8.3 src/Form/EntityUsageSettingsForm.php \Drupal\entity_usage\Form\EntityUsageSettingsForm::submitForm()

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 ConfigFormBase::submitForm

File

src/Form/EntityUsageSettingsForm.php, line 108

Class

EntityUsageSettingsForm
Form to configure entity_usage settings.

Namespace

Drupal\entity_usage\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('entity_usage.settings');
  $form_state
    ->cleanValues();
  foreach ($form_state
    ->getValues() as $key => $value) {
    if ($key == 'local_task_enabled_entity_types') {
      $enabled_entity_types = [];
      foreach ($value as $entity_type_id => $enabled) {
        if ($enabled) {
          $enabled_entity_types[] = $entity_type_id;
        }
      }
      $value = $enabled_entity_types;
    }
    $config
      ->set($key, $value);
  }
  $config
    ->save();
  $this->routerBuilder
    ->rebuild();
  $this->cacheRender
    ->invalidateAll();
  parent::submitForm($form, $form_state);
}