You are here

public function ContainerTrait::genericFieldset in GoogleTagManager 8

Fieldset builder for the container settings form.

3 calls to ContainerTrait::genericFieldset()
ContainerTrait::pathFieldset in src/Form/ContainerTrait.php
Fieldset builder for the container settings form.
ContainerTrait::roleFieldset in src/Form/ContainerTrait.php
Fieldset builder for the container settings form.
ContainerTrait::statusFieldset in src/Form/ContainerTrait.php
Fieldset builder for the container settings form.

File

src/Form/ContainerTrait.php, line 180

Class

ContainerTrait
Defines shared routines for the container and settings forms.

Namespace

Drupal\google_tag\Form

Code

public function genericFieldset(array $config, FormStateInterface &$form_state) {
  $container = $this->container;

  // Gather data.
  $config += [
    'fieldset_description' => '',
    'adjective' => 'selected',
  ];
  extract($config);
  $toggle = "{$singular}_toggle";
  $list = "{$singular}_list";
  $args = [
    '@adjective' => $adjective,
    '@uc_adjective' => ucfirst($adjective),
    '@plural' => $plural,
  ];

  // Build form elements.
  $fieldset = [
    '#type' => 'details',
    '#title' => $fieldset_title,
    '#description' => $fieldset_description,
    '#group' => 'conditions',
  ];
  $fieldset[$toggle] = [
    '#type' => 'radios',
    '#title' => $this
      ->specialT('Insert snippet for specific @plural', $args),
    '#options' => [
      GOOGLE_TAG_EXCLUDE_LISTED => $this
        ->specialT('All @plural except the @adjective @plural', $args),
      GOOGLE_TAG_INCLUDE_LISTED => $this
        ->specialT('Only the @adjective @plural', $args),
    ],
    '#default_value' => $container
      ->get("{$this->prefix}{$toggle}"),
  ];
  if ($adjective == 'selected') {
    $fieldset[$list] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->specialT('@uc_adjective @plural', $args),
      '#options' => $options,
      '#default_value' => $container
        ->get("{$this->prefix}{$list}"),
    ];
  }
  else {
    $fieldset[$list] = [
      '#type' => 'textarea',
      '#title' => $this
        ->specialT('@uc_adjective @plural', $args),
      '#description' => $description,
      '#default_value' => $container
        ->get("{$this->prefix}{$list}"),
      '#rows' => $rows,
    ];
  }
  return $fieldset;
}