You are here

public function AddServices::submitForm in TacJS 8.6

Same name and namespace in other branches
  1. 8.3 src/Form/Steps/AddServices.php \Drupal\tacjs\Form\Steps\AddServices::submitForm()
  2. 8.4 src/Form/Steps/AddServices.php \Drupal\tacjs\Form\Steps\AddServices::submitForm()
  3. 8.5 src/Form/Steps/AddServices.php \Drupal\tacjs\Form\Steps\AddServices::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/Steps/AddServices.php, line 145

Class

AddServices
Class AddServices.

Namespace

Drupal\tacjs\Form\Steps

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('tacjs.settings');
  foreach ($this->content as $type => $services) {
    foreach ($services as $service => $value) {
      $config
        ->set('services.' . $service, [
        "status" => $form_state
          ->getValue('service_' . $service . '_status'),
        "needConsent" => $form_state
          ->getValue('service_' . $service . '_needConsent'),
        "readMore" => $form_state
          ->getValue('service_' . $service . '_readMore'),
        "readmoreLink" => $form_state
          ->getValue('service_' . $service . '_readmoreLink'),
      ]);
      if (preg_match_all('/tarteaucitron.user.([A-z]+)[\\s]+=[\\s]+[\\]?[\\"]?[\']?###([^.]+)###/m', $value['code']['js'] ?: (is_array($value['code']['html']) ? '' : $value['code']['html']), $match)) {
        for ($i = 0; $i < count($match[1]); $i++) {
          if ($form_state
            ->getValue('user_' . $match[1][$i])) {
            $config
              ->set('user.' . $match[1][$i], $form_state
              ->getValue('user_' . $match[1][$i]));
          }
          else {
            $config
              ->clear('user.' . $match[1][$i]);
          }
        }
      }
    }
  }
  $config
    ->save();
  parent::submitForm($form, $form_state);
}