Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Access/AccessResult.php \Drupal\Core\Access\AccessResult::forbiddenIf()
  2. 9 core/lib/Drupal/Core/Access/AccessResult.php \Drupal\Core\Access\AccessResult::forbiddenIf()

Creates a forbidden or neutral access result.

Parameters

bool $condition: The condition to evaluate.

string|null $reason: (optional) The reason why access is forbidden. Intended for developers, hence not translatable

Return value

\Drupal\Core\Access\AccessResult If $condition is TRUE, isForbidden() will be TRUE, otherwise isNeutral() will be TRUE.

14 calls to AccessResult::forbiddenIf()
AccessResultTest::testAccessConditionallyForbidden in core/tests/Drupal/Tests/Core/Access/AccessResultTest.php
@covers ::forbiddenIf @covers ::isAllowed @covers ::isForbidden @covers ::isNeutral
AccessResultTest::testAccessForbiddenReason in core/tests/Drupal/Tests/Core/Access/AccessResultTest.php
@covers ::forbidden
config_test_rest_config_test_access in core/modules/rest/tests/modules/config_test_rest/config_test_rest.module
Implements hook_ENTITY_TYPE_access().
EntityAccess::entityOperationAccess in core/modules/workspaces/src/EntityAccess.php
Implements a hook bridge for hook_entity_access().
field_test_boolean_access_denied_entity_field_access in core/modules/field/tests/modules/field_test_boolean_access_denied/field_test_boolean_access_denied.module
Implements hook_entity_field_access().

... See full list

File

core/lib/Drupal/Core/Access/AccessResult.php, line 96

Class

AccessResult
Value object for passing an access result with cacheability metadata.

Namespace

Drupal\Core\Access

Code

public static function forbiddenIf($condition, $reason = NULL) {
  return $condition ? static::forbidden($reason) : static::neutral();
}