You are here

protected function ContainerForm::conditionsForm in GoogleTagManager 8

Builds the form elements for the insertion conditions.

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 augmented form array with the insertion condition elements.

1 call to ContainerForm::conditionsForm()
ContainerForm::form in src/Form/ContainerForm.php
Gets the actual form array to be built.

File

src/Form/ContainerForm.php, line 181

Class

ContainerForm
Defines the Google tag manager container settings form.

Namespace

Drupal\google_tag\Form

Code

protected function conditionsForm(array $form, FormStateInterface $form_state) {
  $conditions = $this->entity
    ->getInsertionConditions();

  // See core/lib/Drupal/Core/Plugin/FilteredPluginManagerTrait.php
  // The next method calls alter hooks to filter the definitions.
  // Implement one of the hooks in this module.
  $definitions = $this->conditionManager
    ->getFilteredDefinitions('google_tag', $form_state
    ->getTemporaryValue('gathered_contexts'), [
    'google_tag_container' => $this->entity,
  ]);
  ksort($definitions);
  $form_state
    ->setTemporaryValue('filtered_conditions', array_keys($definitions));
  foreach ($definitions as $condition_id => $definition) {
    if ($conditions
      ->has($condition_id)) {
      $condition = $conditions
        ->get($condition_id);
    }
    else {

      /** @var \Drupal\Core\Condition\ConditionInterface $condition */
      $condition = $this->conditionManager
        ->createInstance($condition_id, []);
    }
    $form_state
      ->set([
      'conditions',
      $condition_id,
    ], $condition);
    $form[$condition_id] = $this
      ->conditionFieldset($condition, $form_state);
  }

  /*
      // Add comment to first condition tab.
      // @todo This would apply if all insertion conditions were converted to
      // condition plugins.
      $description = $this->t('On this and the following tabs, specify the conditions on which the GTM JavaScript snippet will either be inserted on or omitted from the page response, thereby enabling or disabling tracking and other analytics. All conditions must be satisfied for the snippet to be inserted. The snippet will be omitted if any condition is not met.');
      $condition_id = current(array_keys($definitions));
      $form[$condition_id]['#description'] = $description;
  */
  return $form;
}