You are here

public function SettingsForm::buildForm in GoogleTag Manager 8

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/SettingsForm.php, line 30

Class

SettingsForm
Implements the form controller.

Namespace

Drupal\gtm\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('gtm.settings');
  $form['general'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('General settings'),
    '#open' => TRUE,
  ];
  $form['general']['enable'] = [
    '#title' => $this
      ->t('Enable Google Tag Manager'),
    '#description' => $this
      ->t('Add GTM code on website pages'),
    '#type' => 'checkbox',
    '#maxlength' => 20,
    '#required' => FALSE,
    '#size' => 15,
    '#default_value' => $config
      ->get('enable'),
  ];
  $form['general']['admin-pages'] = [
    '#title' => $this
      ->t('Display Google Tag Manager on admin pages (if GTM enabled)'),
    '#description' => $this
      ->t('Add GTM code on admin pages'),
    '#type' => 'checkbox',
    '#maxlength' => 20,
    '#required' => FALSE,
    '#size' => 15,
    '#default_value' => $config
      ->get('admin-pages'),
  ];
  $form['general']['admin-disable'] = [
    '#title' => $this
      ->t('Disable for admin'),
    '#description' => $this
      ->t('Do not use GTM for User with uid=1'),
    '#type' => 'checkbox',
    '#maxlength' => 20,
    '#required' => FALSE,
    '#size' => 15,
    '#default_value' => $config
      ->get('admin-disable'),
  ];
  $form['general']['google-tag'] = [
    '#title' => $this
      ->t('GTM-ID'),
    '#default_value' => $config
      ->get('google-tag'),
    '#maxlength' => 20,
    '#size' => 15,
    '#type' => 'textfield',
    '#description' => $this
      ->t("You can add site to\n        <a target='_blank' href='https://tagmanager.google.com/?hl=@lang'>Google Tag Manager</a>", [
      '@lang' => \Drupal::languageManager()
        ->getCurrentLanguage()
        ->getId(),
    ]),
  ];
  return parent::buildForm($form, $form_state);
}