You are here

public function AddServices::buildForm in TacJS 8.5

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

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

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

Class

AddServices
Class AddServices.

Namespace

Drupal\tacjs\Form\Steps

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('tacjs.settings');
  $form['services'] = [
    '#type' => 'vertical_tabs',
    '#title' => $this
      ->t('Add Services'),
    '#title_display' => 'invisible',
  ];
  foreach ($this->content as $type => $services) {
    $form['service']['type_' . $type] = [
      '#type' => 'details',
      '#title' => Unicode::ucfirst($type),
      '#group' => 'services',
    ];
    foreach ($services as $service => $value) {
      $form['service']['type_' . $type]['service_' . $service] = [
        '#type' => 'checkbox',
        '#title' => $value['about']['name'],
        '#default_value' => $config
          ->get('services.' . $service),
      ];
      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['service']['type_' . $type]['user_' . $match[1][$i]] = [
            '#type' => 'textfield',
            '#title' => $match[1][$i],
            '#default_value' => $config
              ->get('user.' . $match[1][$i]),
            '#title_display' => 'invisible',
            '#attributes' => [
              'placeholder' => $match[2][$i],
            ],
            '#states' => [
              'visible' => [
                ':input[name="service_' . $service . '"]' => [
                  'checked' => TRUE,
                ],
              ],
            ],
          ];
        }
      }
    }
  }

  // Workaround for #3170835: Uncaught TypeError null user
  // See https://github.com/AmauriC/tarteaucitron.js/pull/394
  $form['service']['type_analytic']['user_multiplegtagUa']['#attributes']['placeholder'] = 'UA-XXXXXXXX-X,UA-XXXXXXXX-X,UA-XXXXXXXX-X';
  return parent::buildForm($form, $form_state);
}