View source
<?php
namespace Drupal\analytics\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class AnalyticsSettingsForm extends ConfigFormBase {
public function getFormId() {
return 'analytics_settings_form';
}
protected function getEditableConfigNames() {
return [
'analytics.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('analytics.settings');
$form['privacy'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Privacy'),
'#tree' => TRUE,
];
$form['privacy']['dnt'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Respect Do Not Track (DNT) cookies.'),
'#default_value' => $config
->get('privacy.dnt'),
];
$form['privacy']['disable_floc'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Opt out of <a href=":link">Federated Learning of Cohorts (FLoC) browser-based targeted advertising tracking</a>.', [
':link' => 'https://www.eff.org/deeplinks/2021/03/googles-floc-terrible-idea',
]),
'#default_value' => $config
->get('privacy.disable_floc'),
];
$form['advanced'] = [
'#type' => 'details',
'#title' => $this
->t('Advanced'),
'#open' => FALSE,
];
$form['advanced']['cache_urls'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Cache files locally where possible.'),
'#default_value' => $config
->get('cache_urls'),
];
$form['advanced']['disable_page_build'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Disable default analytics service rendering in hook_page_bottom().'),
'#default_value' => $config
->get('disable_page_build'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('analytics.settings')
->set('privacy', $form_state
->getValue('privacy'))
->set('cache_urls', $form_state
->getValue('cache_urls'))
->set('disable_page_build', $form_state
->getValue('disable_page_build'))
->save();
parent::submitForm($form, $form_state);
}
}