You are here

protected function ContainerAccessControlHandler::resolveConditions in GoogleTagManager 8

1 call to ContainerAccessControlHandler::resolveConditions()
ContainerAccessControlHandler::checkAccess in src/ContainerAccessControlHandler.php
Performs access checks.

File

src/ContainerAccessControlHandler.php, line 203

Class

ContainerAccessControlHandler
Defines access control for the container configuration entity type.

Namespace

Drupal\google_tag

Code

protected function resolveConditions(array $conditions, $condition_logic) {
  foreach ($conditions as $condition_id => $condition) {
    try {
      if (in_array($condition_id, [
        'gtag_domain',
        'gtag_language',
      ])) {

        // Avoid call to execute() as it involves the 'negate' element removed
        // from our condition plugins.
        $pass = $condition
          ->evaluate();
      }
      else {

        // The condition plugin is not defined by this module.
        $pass = $condition
          ->execute();
      }
    } catch (ContextException $e) {

      // The condition is missing context; consider that a pass.
      // Example: node bundle condition and the page request is not a node.
      // Because the context is missing, the condition is not applicable.
      $pass = TRUE;
    }
    $this->entity
      ->displayMessage('@condition check @satisfied', [
      '@condition' => str_replace('gtag_', '', $condition_id),
      '@satisfied' => $pass,
    ]);
    if (!$pass && $condition_logic == 'and') {

      // This condition failed and all conditions are needed; deny access.
      return FALSE;
    }
    elseif ($pass && $condition_logic == 'or') {

      // This condition passed and only one condition is needed; grant access.
      return TRUE;
    }
  }

  // Return TRUE if logic was 'and', meaning all rules passed.
  // Return FALSE if logic was 'or', meaning no rule passed.
  return $condition_logic == 'and';
}