You are here

public function SettingsForm::buildForm in CookieConsent 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 68
Contains Drupal\cookieconsent\Form\SettingsForm.

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\cookieconsent\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('cookieconsent.settings');
  $form['minified'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use the minified version (cookieconsent.min.js) of the Cookie Consent javascript plugin'),
    '#description' => $this
      ->t('If you want to be able to debug the javascript (by using cookieconsent.js), uncheck this box.'),
    '#default_value' => $config
      ->get('minified'),
  ];
  $form['theme'] = [
    '#type' => 'select',
    '#options' => [
      'none' => $this
        ->t('- None -'),
      'dark-top' => $this
        ->t('Dark Top'),
      'dark-floating' => $this
        ->t('Dark Floating'),
      'dark-bottom' => $this
        ->t('Dark Bottom'),
      'light-floating' => $this
        ->t('Light Floating'),
      'light-top' => $this
        ->t('Light Top'),
      'light-bottom' => $this
        ->t('Light Bottom'),
    ],
    '#title' => $this
      ->t('Choose your theme'),
    '#description' => $this
      ->t('Select the theme you wish to use.'),
    '#default_value' => $config
      ->get('theme'),
  ];
  $form['theme_path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path to custom CSS file'),
    '#description' => $this
      ->t('Specify the path to the custom CSS file to use (e.g. <em>themes/[your-theme]/css/cookie-consent.css</em>). This custom CSS file will load only if NO theme is specified above.'),
    '#maxlength' => 255,
    '#size' => 64,
    '#default_value' => $config
      ->get('theme_path'),
  ];
  $form['texts'] = [
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#title' => $this
      ->t('Custom texts'),
  ];
  $form['texts']['customise'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Customise the text'),
    '#description' => $this
      ->t('Customise the text used on the cookie bar'),
    '#default_value' => $config
      ->get('customise'),
  ];
  $form['texts']['headline_text'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Headline Text'),
    '#description' => $this
      ->t('The message shown by the plugin.'),
    '#rows' => 2,
    '#default_value' => $config
      ->get('headline_text'),
    '#states' => [
      'visible' => [
        ':input[name="customise"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['texts']['accept_button_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Accept button text'),
    '#maxlength' => 255,
    '#size' => 64,
    '#default_value' => $config
      ->get('accept_button_text'),
    '#states' => [
      'visible' => [
        ':input[name="customise"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['texts']['read_more_button_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Read more button text'),
    '#description' => $this
      ->t('The text shown on the link to the cookie policy (requires the Cookie policy option to also be set)'),
    '#maxlength' => 255,
    '#size' => 64,
    '#default_value' => $config
      ->get('read_more_button_text'),
    '#states' => [
      'visible' => [
        ':input[name="customise"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['cookie_policy'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'node',
    '#title' => $this
      ->t('Your cookie policy'),
    '#description' => $this
      ->t('If you already have a cookie policy, link to it here.'),
    '#maxlength' => 255,
    '#size' => 64,
    '#default_value' => $config
      ->get('cookie_policy') ? $this->entityTypeManager
      ->getStorage('node')
      ->load($config
      ->get('cookie_policy')) : NULL,
  ];
  $form['container'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Container Element'),
    '#description' => $this
      ->t('The element you want the Cookie Consent notification to be appended to. When left empty, the Cookie Consent plugin is appended to the body.'),
    '#maxlength' => 255,
    '#size' => 64,
    '#default_value' => $config
      ->get('container'),
  ];
  $form['path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path'),
    '#description' => $this
      ->t('The path for the consent cookie that Cookie Consent uses, to remember that users have consented to cookies. Use to limit consent to a specific path within your website.'),
    '#maxlength' => 255,
    '#size' => 64,
    '#default_value' => $config
      ->get('path'),
  ];
  $form['expiry'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Expiry days'),
    '#description' => $this
      ->t('The number of days Cookie Consent should store the user’s consent information for.'),
    '#maxlength' => 255,
    '#size' => 64,
    '#default_value' => $config
      ->get('expiry'),
  ];
  $form['target'] = [
    '#type' => 'select',
    '#options' => [
      '_blank' => t('_blank (a new window or tab)'),
      '_self' => t('_self (the same frame as it was clicked)'),
      '_parent' => t('_parent (the parent frame)'),
      '_top' => t('_top (the full body of the window)'),
    ],
    '#title' => $this
      ->t('Target'),
    '#description' => $this
      ->t('The <em>target</em> of the link to your cookie policy. Use to open a link in a new window, if you wish.'),
    '#default_value' => !empty($config
      ->get('target')) ? $config
      ->get('target') : '_self',
  ];
  return parent::buildForm($form, $form_state);
}