function 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.
9 calls to AccessResult::forbiddenIf()
- AccessResultTest::testAccessConditionallyForbidden in core/tests/ Drupal/ Tests/ Core/ Access/ AccessResultTest.php 
- Tests access conditionally forbidden.
- AccessResultTest::testAccessForbiddenReason in core/tests/ Drupal/ Tests/ Core/ Access/ AccessResultTest.php 
- Tests access forbidden reason.
- BlockContentAccessControlHandler::checkAccess in core/modules/ block_content/ src/ BlockContentAccessControlHandler.php 
- Performs access checks.
- FieldTestBooleanAccessDeniedHooks::entityFieldAccess in core/modules/ field/ tests/ modules/ field_test_boolean_access_denied/ src/ Hook/ FieldTestBooleanAccessDeniedHooks.php 
- Implements hook_entity_field_access().
- FieldUiTestHooks::fieldConfigAccess in core/modules/ field_ui/ tests/ modules/ field_ui_test/ src/ Hook/ FieldUiTestHooks.php 
- Implements hook_ENTITY_TYPE_access().
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\AccessCode
public static function forbiddenIf($condition, $reason = NULL) {
  return $condition ? static::forbidden($reason) : static::neutral();
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
