You are here

public function ContainerTrait::advancedFieldset in GoogleTagManager 8

Fieldset builder for the container settings form.

2 calls to ContainerTrait::advancedFieldset()
ContainerForm::form in src/Form/ContainerForm.php
Gets the actual form array to be built.
SettingsForm::buildForm in src/Form/SettingsForm.php
Form constructor.

File

src/Form/ContainerTrait.php, line 29

Class

ContainerTrait
Defines shared routines for the container and settings forms.

Namespace

Drupal\google_tag\Form

Code

public function advancedFieldset(FormStateInterface &$form_state) {
  $container = $this->container;

  // Build form elements.
  $fieldset = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced'),
    '#group' => 'settings',
  ];
  $fieldset['data_layer'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Data layer'),
    '#description' => $this
      ->t('The name of the data layer. Default value is "dataLayer". In most cases, use the default.'),
    '#default_value' => $container
      ->get("{$this->prefix}data_layer"),
    '#attributes' => [
      'placeholder' => [
        'dataLayer',
      ],
    ],
    '#required' => TRUE,
  ];
  $fieldset['include_classes'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Add classes to the data layer'),
    '#description' => $this
      ->t('If checked, then the listed classes will be added to the data layer.'),
    '#default_value' => $container
      ->get("{$this->prefix}include_classes"),
  ];
  $description = $this
    ->t('The types of tags, triggers, and variables <strong>allowed</strong> on a page. Enter one class per line. For more information, refer to the <a href="https://developers.google.com/tag-manager/devguide#security">developer documentation</a>.');
  $fieldset['whitelist_classes'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('White-listed classes'),
    '#description' => $description,
    '#default_value' => $container
      ->get("{$this->prefix}whitelist_classes"),
    '#rows' => 5,
    '#states' => $this
      ->statesArray('include_classes'),
  ];
  $fieldset['blacklist_classes'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Black-listed classes'),
    '#description' => $this
      ->t('The types of tags, triggers, and variables <strong>forbidden</strong> on a page. Enter one class per line.'),
    '#default_value' => $container
      ->get("{$this->prefix}blacklist_classes"),
    '#rows' => 5,
    '#states' => $this
      ->statesArray('include_classes'),
  ];
  $fieldset['include_environment'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Include an environment'),
    '#description' => $this
      ->t('If checked, then the applicable snippets will include the environment items below. Enable <strong>only for development</strong> purposes.'),
    '#default_value' => $container
      ->get("{$this->prefix}include_environment"),
  ];
  $description = $this
    ->t('The environment ID to use with this website container. To get an environment ID, <a href="https://tagmanager.google.com/#/admin">select Environments</a>, create an environment, then click the "Get Snippet" action. The environment ID and token will be in the snippet.');
  $fieldset['environment_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Environment ID'),
    '#description' => $description,
    '#default_value' => $container
      ->get("{$this->prefix}environment_id"),
    '#attributes' => [
      'placeholder' => [
        'env-x',
      ],
    ],
    '#size' => 10,
    '#maxlength' => 7,
    '#states' => $this
      ->statesArray('include_environment'),
  ];
  $fieldset['environment_token'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Environment token'),
    '#description' => $this
      ->t('The authentication token for this environment.'),
    '#default_value' => $container
      ->get("{$this->prefix}environment_token"),
    '#attributes' => [
      'placeholder' => [
        'xxxxxxxxxxxxxxxxxxxxxx',
      ],
    ],
    '#size' => 20,
    '#maxlength' => 25,
    '#states' => $this
      ->statesArray('include_environment'),
  ];
  return $fieldset;
}