You are here

public function YandexMetricsCounterSettingsForm::buildForm in Yandex.Metrics 8.3

Same name and namespace in other branches
  1. 8.2 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\Form

Code

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' => $this
      ->t('Counter Code'),
    '#type' => 'textarea',
    '#rows' => 10,
    '#description' => $this
      ->t('Paste Yandex.Metrics counter code for your site here.'),
  );
  $form['path'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Page specific tracking settings'),
    '#collapsed' => TRUE,
  );
  $visibility = $config
    ->get('visibility.path.visibility');
  $options = array(
    $this
      ->t('Add to every page except the listed pages.'),
    $this
      ->t('Add to the listed pages only.'),
  );
  $form['path']['visibility'] = array(
    '#type' => 'radios',
    '#title' => $this
      ->t('Add code to specific pages'),
    '#options' => $options,
    '#default_value' => $visibility,
  );
  $pages = $config
    ->get('visibility.path.pages');
  $description = $this
    ->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' => $this
      ->t('Pages'),
    '#default_value' => $pages,
    '#description' => $description,
    '#wysiwyg' => FALSE,
    '#rows' => 10,
  );

  // Render the role overview.
  $form['role'] = array(
    '#type' => 'details',
    '#title' => $this
      ->t('Role specific tracking settings'),
    '#collapsed' => TRUE,
  );
  $form['role']['visibility_roles'] = array(
    '#type' => 'radios',
    '#title' => $this
      ->t('Add tracking for specific roles'),
    '#options' => array(
      $this
        ->t('Add to the selected roles only'),
      $this
        ->t('Add to every role except the selected ones'),
    ),
    '#default_value' => $config
      ->get('visibility.role.visibility'),
  );
  $role_options = array_map('\\Drupal\\Component\\Utility\\Html::escape', user_role_names());
  $form['role']['roles'] = array(
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Roles'),
    '#default_value' => $config
      ->get('visibility.role.roles'),
    '#options' => $role_options,
    '#description' => $this
      ->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);
}