You are here

public function Filter::isAllowed in Access Filter 8

Checks the current access is allowed using the filter.

Parameters

\Symfony\Component\HttpFoundation\Request $request: A request instance.

Return value

bool Boolean TRUE if allowed, FALSE otherwise.

Overrides FilterInterface::isAllowed

File

src/Entity/Filter.php, line 206

Class

Filter
Defines the Filter entity.

Namespace

Drupal\access_filter\Entity

Code

public function isAllowed(Request $request) {
  $is_matched = FALSE;
  foreach ($this->parsedConditions as $condition) {
    $is_matched = $condition
      ->isMatched($request);
    if ($condition
      ->isNegated()) {
      $is_matched = !$is_matched;
    }
    if ($is_matched) {
      break;
    }
  }
  if (!$is_matched) {
    return TRUE;
  }
  $is_allowed = TRUE;
  foreach ($this->parsedRules as $rule) {
    $result = $rule
      ->check($request);
    if ($result
      ->isAllowed()) {
      $is_allowed = TRUE;
    }
    elseif ($result
      ->isForbidden()) {
      $is_allowed = FALSE;
    }
  }
  return $is_allowed;
}