You are here

public function TrackFieldChangesAdminSettings::submitForm in Track Field Changes 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 ConfigFormBase::submitForm

File

src/Form/TrackFieldChangesAdminSettings.php, line 150
Contains \Drupal\track_field_changes\Form\TrackFieldChangesAdminSettings.

Class

TrackFieldChangesAdminSettings

Namespace

Drupal\track_field_changes\Form

Code

public function submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $config = $this
    ->config('track_field_changes.settings');
  foreach (\Drupal::entityTypeManager()
    ->getDefinitions() as $entity_type_id => $entity_type) {
    $vals = $form_state
      ->getValue($entity_type_id);
    $vals['bundle_types'] = array_filter($vals['bundle_types']);
    if (empty($vals['bundle_types'])) {
      $config
        ->clear($entity_type_id);
    }
    else {
      foreach ($vals as $bundle_type_id => $opts) {
        if ($bundle_type_id == 'bundle_types') {
          continue;
        }
        elseif (empty($vals[$bundle_type_id])) {
          unset($vals[$bundle_type_id]);
        }
        else {
          $vals[$bundle_type_id]['fields'] = array_filter($vals[$bundle_type_id]['fields']);
        }
      }
      $config
        ->set($entity_type_id, $vals);
    }
  }
  $config
    ->save();
  \Drupal::service('views.views_data')
    ->clear();
  parent::submitForm($form, $form_state);
}