You are here

protected function EloquaSettingsForm::buildTrackignScopeInterface in Eloqua 8

Helper function for building the tracking scope UI form.

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 array with the tracking scope UI added in.

1 call to EloquaSettingsForm::buildTrackignScopeInterface()
EloquaSettingsForm::buildForm in src/Form/EloquaSettingsForm.php
Form constructor.

File

src/Form/EloquaSettingsForm.php, line 127
Contains \Drupal\eloqua\Form\EloquaSettingsForm.

Class

EloquaSettingsForm
Configure Eloqua settings for this site.

Namespace

Drupal\Eloqua\Form

Code

protected function buildTrackignScopeInterface(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('eloqua.settings');
  $form['tracking_scope'] = array(
    '#type' => 'item',
    '#title' => $this
      ->t('Tracking scope'),
    '#description' => $this
      ->t('Configuration to include/exclude the Eloqua tracking code.'),
  );
  $form['tracking_scope_tabs'] = [
    '#type' => 'vertical_tabs',
    '#title' => $this
      ->t('Tracking Scope Conditions'),
    '#title_display' => 'invisible',
    '#parents' => [
      'tracking_scope_tabs',
    ],
    '#attached' => [
      'library' => [
        'eloqua/eloqua.admin',
      ],
    ],
  ];

  // Set the condition configuration.
  $this->requestPath
    ->setConfiguration($config
    ->get('request_path'));
  $this->userRole
    ->setConfiguration($config
    ->get('user_role'));

  // Build the request_path condition configuration form elements.
  $form += $this->requestPath
    ->buildConfigurationForm($form, $form_state);
  if (isset($form['pages'])) {
    $form['pages']['pages'] = $form['pages'];
    $form['pages']['negate'] = $form['negate'];
    unset($form['pages']['#description']);
    unset($form['negate']);
    $form['pages']['#type'] = 'details';
    $form['pages']['#group'] = 'tracking_scope_tabs';
    $form['pages']['#title'] = $this
      ->t('Pages');
    $form['pages']['negate']['#type'] = 'radios';
    $form['pages']['negate']['#title_display'] = 'invisible';
    $form['pages']['negate']['#options'] = [
      $this
        ->t('Show for the listed pages'),
      $this
        ->t('Hide for the listed pages'),
    ];

    // Switch negate default value form boolean to integer.
    // Solves issue related to https://www.drupal.org/node/2450637.
    $form['pages']['negate']['#default_value'] = $form['pages']['negate']['#default_value'] === FALSE ? 0 : 1;
  }

  // Build the user_role condition configuration form elements.
  $form += $this->userRole
    ->buildConfigurationForm($form, $form_state);
  if (isset($form['roles'])) {
    $form['roles']['roles'] = $form['roles'];
    $form['roles']['negate'] = $form['negate'];
    unset($form['roles']['#description']);
    unset($form['negate']);
    $form['roles']['#type'] = 'details';
    $form['roles']['#group'] = 'tracking_scope_tabs';
    $form['roles']['#title'] = $this
      ->t('Roles');
    $form['roles']['negate']['#type'] = 'value';
    $form['roles']['negate']['#default_value'] = FALSE;
  }
  return $form;
}