public function YandexMetricsCounterSettingsForm::buildForm in Yandex.Metrics 8.2
Same name and namespace in other branches
- 8.3 src/Form/YandexMetricsCounterSettingsForm.php \Drupal\yandex_metrics\Form\YandexMetricsCounterSettingsForm::buildForm()
Implements \Drupal\Core\Form\FormInterface::buildForm().
Overrides ConfigFormBase::buildForm
File
- src/
Form/ YandexMetricsCounterSettingsForm.php, line 36 - Contains \Drupal\yandex_metrics\Form\YandexMetricsCounterSettingsForm.
Class
- YandexMetricsCounterSettingsForm
- Provides a form for configuring Yandex.Metrics counter settings.
Namespace
Drupal\yandex_metrics\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $action = NULL) {
// Create config object.
$config = \Drupal::config('yandex_metrics.settings');
$form['counter_code'] = array(
'#default_value' => $config
->get('counter_code'),
'#title' => t('Counter Code'),
'#type' => 'textarea',
'#rows' => 10,
'#description' => t('Paste Yandex.Metrics counter code for your site here.'),
);
$form['path'] = array(
'#type' => 'details',
'#title' => t('Page specific tracking settings'),
'#collapsed' => TRUE,
);
$visibility = $config
->get('visibility.path.visibility');
$options = array(
t('Add to every page except the listed pages.'),
t('Add to the listed pages only.'),
);
$form['path']['visibility'] = array(
'#type' => 'radios',
'#title' => t('Add code to specific pages'),
'#options' => $options,
'#default_value' => $visibility,
);
$pages = $config
->get('visibility.path.pages');
$description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
'%blog' => 'blog',
'%blog-wildcard' => 'blog/*',
'%front' => '<front>',
));
$form['path']['pages'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
'#default_value' => $pages,
'#description' => $description,
'#wysiwyg' => FALSE,
'#rows' => 10,
);
// Render the role overview.
$form['role'] = array(
'#type' => 'details',
'#title' => t('Role specific tracking settings'),
'#collapsed' => TRUE,
);
$form['role']['visibility_roles'] = array(
'#type' => 'radios',
'#title' => t('Add tracking for specific roles'),
'#options' => array(
t('Add to the selected roles only'),
t('Add to every role except the selected ones'),
),
'#default_value' => $config
->get('visibility.role.visibility'),
);
$role_options = array_map('Drupal\\Component\\Utility\\String::checkPlain', user_role_names());
$form['role']['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Roles'),
'#default_value' => $config
->get('visibility.role.roles'),
'#options' => $role_options,
'#description' => t('If none of the roles are selected, all users will be tracked. If a user has any of the roles checked, that user will be tracked (or excluded, depending on the setting above).'),
);
return parent::buildForm($form, $form_state);
}