You are here

public function AddServices::validateForm in TacJS 8.5

Same name and namespace in other branches
  1. 8.6 src/Form/Steps/AddServices.php \Drupal\tacjs\Form\Steps\AddServices::validateForm()
  2. 8.3 src/Form/Steps/AddServices.php \Drupal\tacjs\Form\Steps\AddServices::validateForm()
  3. 8.4 src/Form/Steps/AddServices.php \Drupal\tacjs\Form\Steps\AddServices::validateForm()

Form validation 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 FormBase::validateForm

File

src/Form/Steps/AddServices.php, line 103

Class

AddServices
Class AddServices.

Namespace

Drupal\tacjs\Form\Steps

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  foreach ($this->content as $type => $services) {
    foreach ($services as $service => $value) {
      $form_state
        ->setValue('service_' . $service, $form_state
        ->getValue('service_' . $service) ? TRUE : FALSE);
      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++) {
          $form_state
            ->setValue('user_' . $match[1][$i], $form_state
            ->getValue('user_' . $match[1][$i]) ?: NULL);
        }
      }
    }
  }
  parent::validateForm($form, $form_state);
}