AccessResult::allowedIfHasPermission

public static AccessResult::allowedIfHasPermission(AccountInterface $account, $permission)

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.

File

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

Class

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

Namespace

Drupal\Core\Access

Code

public static function allowedIfHasPermission(AccountInterface $account, $permission) {
  return static::allowedIf($account->hasPermission($permission))->addCacheContexts(['user.permissions']);
}
doc_Drupal
2016-10-29 08:42:29
Comments
Leave a Comment

Please login to continue.