public function AddServices::buildForm in TacJS 8.6
Same name and namespace in other branches
- 8.3 src/Form/Steps/AddServices.php \Drupal\tacjs\Form\Steps\AddServices::buildForm()
- 8.4 src/Form/Steps/AddServices.php \Drupal\tacjs\Form\Steps\AddServices::buildForm()
- 8.5 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\StepsCode
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 . '_status'] = [
'#type' => 'checkbox',
'#title' => $value['about']['name'],
'#default_value' => $config
->get('services.' . $service . '.status'),
];
$form['service']['type_' . $type]['details_' . $service] = [
'#type' => 'fieldset',
'#title' => 'Configuration',
'#states' => [
'visible' => [
':input[name="service_' . $service . '_status"]' => [
'checked' => TRUE,
],
],
],
];
$form['service']['type_' . $type]['details_' . $service]['service_' . $service . '_readMore'] = [
'#type' => 'textarea',
'#title' => $this
->t('More info'),
'#default_value' => $config
->get('services.' . $service . '.readMore'),
];
$form['service']['type_' . $type]['details_' . $service]['service_' . $service . '_needConsent'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Need consent'),
'#default_value' => $config
->get('services.' . $service . '.needConsent'),
];
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]['details_' . $service]['user_' . $match[1][$i]] = [
'#type' => 'textfield',
'#title' => $match[1][$i],
'#default_value' => $config
->get('user.' . $match[1][$i]),
'#title_display' => 'invisible',
'#maxlength' => 255,
'#attributes' => [
'placeholder' => $match[2][$i],
],
];
}
}
}
}
// 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';
// Workaround for #3204238: Uncaught TypeError null user
// See https://www.drupal.org/project/tacjs/issues/3204238
$form['service']['type_api']['user_googleFonts']['#attributes']['placeholder'] = 'My Font, My Other:300,700';
return parent::buildForm($form, $form_state);
}