function AccessResult::allowedIfHasPermission
Creates an allowed access result if the permission is present, neutral otherwise.
Checks the permission and adds a 'user.permissions' cache context.
Parameters
\Drupal\Core\Session\AccountInterface $account: The account for which to check a permission.
string $permission: The permission to check for.
Return value
\Drupal\Core\Access\AccessResult If the account has the permission, isAllowed() will be TRUE, otherwise isNeutral() will be TRUE.
50 calls to AccessResult::allowedIfHasPermission()
- AnnounceBlock::blockAccess in core/
modules/ announcements_feed/ src/ Plugin/ Block/ AnnounceBlock.php - Indicates whether the block should be shown.
- BaseFieldOverrideAccessControlHandler::checkAccess in core/
lib/ Drupal/ Core/ Field/ BaseFieldOverrideAccessControlHandler.php - Performs access checks.
- CommentAccessControlHandler::checkCreateAccess in core/
modules/ comment/ src/ CommentAccessControlHandler.php - Performs create access checks.
- CommentAccessControlHandler::checkFieldAccess in core/
modules/ comment/ src/ CommentAccessControlHandler.php - Default field access as determined by this access control handler.
- CommentController::replyFormAccess in core/
modules/ comment/ src/ Controller/ CommentController.php - Access check for the reply form.
File
-
core/
lib/ Drupal/ Core/ Access/ AccessResult.php, line 114
Class
- AccessResult
- Value object for passing an access result with cacheability metadata.
Namespace
Drupal\Core\AccessCode
public static function allowedIfHasPermission(AccountInterface $account, $permission) {
$access_result = static::allowedIf($account->hasPermission($permission))
->addCacheContexts([
'user.permissions',
]);
if ($access_result instanceof AccessResultReasonInterface) {
$access_result->setReason("The '{$permission}' permission is required.");
}
return $access_result;
}