abstract class GroupAccessResult in Group 8
Same name and namespace in other branches
- 2.0.x src/Access/GroupAccessResult.php \Drupal\group\Access\GroupAccessResult
Extends the AccessResult class with group permission checks.
Hierarchy
- class \Drupal\Core\Access\AccessResult implements AccessResultInterface, RefinableCacheableDependencyInterface uses RefinableCacheableDependencyTrait
- class \Drupal\group\Access\GroupAccessResult
Expanded class hierarchy of GroupAccessResult
6 files declare their use of GroupAccessResult
- GroupAccessControlHandler.php in src/
Entity/ Access/ GroupAccessControlHandler.php - GroupContentAccessControlHandler.php in src/
Plugin/ GroupContentAccessControlHandler.php - GroupContentEnablerBase.php in src/
Plugin/ GroupContentEnablerBase.php - GroupLatestRevisionCheck.php in src/
Entity/ Access/ GroupLatestRevisionCheck.php - GroupMembership.php in src/
Plugin/ GroupContentEnabler/ GroupMembership.php
File
- src/
Access/ GroupAccessResult.php, line 12
Namespace
Drupal\group\AccessView source
abstract class GroupAccessResult extends AccessResult {
/**
* Allows access if the permission is present, neutral otherwise.
*
* @todo Keep an eye on the following with regard to using the current user:
* - https://www.drupal.org/node/2628870
* - https://www.drupal.org/node/2667018
*
* @param \Drupal\group\Entity\GroupInterface $group
* The group for which to check a permission.
* @param \Drupal\Core\Session\AccountInterface $account
* The account for which to check a permission.
* @param string $permission
* The permission to check for.
*
* @return \Drupal\Core\Access\AccessResult
* If the account has the permission, isAllowed() will be TRUE, otherwise
* isNeutral() will be TRUE.
*/
public static function allowedIfHasGroupPermission(GroupInterface $group, AccountInterface $account, $permission) {
return static::allowedIf($group
->hasPermission($permission, $account))
->addCacheContexts([
'user.group_permissions',
]);
}
/**
* Allows access if the permissions are present, neutral otherwise.
*
* @todo Keep an eye on the following with regard to using the current user:
* - https://www.drupal.org/node/2628870
* - https://www.drupal.org/node/2667018
*
* @param \Drupal\group\Entity\GroupInterface $group
* The group for which to check permissions.
* @param \Drupal\Core\Session\AccountInterface $account
* The account for which to check permissions.
* @param array $permissions
* The permissions to check.
* @param string $conjunction
* (optional) 'AND' if all permissions are required, 'OR' in case just one.
* Defaults to 'AND'.
*
* @return \Drupal\Core\Access\AccessResult
* If the account has the permissions, isAllowed() will be TRUE, otherwise
* isNeutral() will be TRUE.
*/
public static function allowedIfHasGroupPermissions(GroupInterface $group, AccountInterface $account, array $permissions, $conjunction = 'AND') {
$access = FALSE;
if ($conjunction == 'AND' && !empty($permissions)) {
$access = TRUE;
foreach ($permissions as $permission) {
if (!$group
->hasPermission($permission, $account)) {
$access = FALSE;
break;
}
}
}
else {
foreach ($permissions as $permission) {
if ($group
->hasPermission($permission, $account)) {
$access = TRUE;
break;
}
}
}
return static::allowedIf($access)
->addCacheContexts([
'user.group_permissions',
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessResult:: |
public static | function | Creates an AccessResultInterface object with isAllowed() === TRUE. | |
AccessResult:: |
public static | function | Creates an allowed or neutral access result. | |
AccessResult:: |
public static | function | Creates an allowed access result if the permission is present, neutral otherwise. | |
AccessResult:: |
public static | function | Creates an allowed access result if the permissions are present, neutral otherwise. | |
AccessResult:: |
public | function |
Combine this access result with another using AND. Overrides AccessResultInterface:: |
|
AccessResult:: |
public | function | Convenience method, adds the "user.permissions" cache context. | |
AccessResult:: |
public | function | Convenience method, adds the "user" cache context. | |
AccessResult:: |
public | function | Convenience method, adds the configuration object's cache tag. | |
AccessResult:: |
public | function | Convenience method, adds the entity's cache tag. | |
AccessResult:: |
public static | function | Creates an AccessResultInterface object with isForbidden() === TRUE. | |
AccessResult:: |
public static | function | Creates a forbidden or neutral access result. | |
AccessResult:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyTrait:: |
|
AccessResult:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyTrait:: |
|
AccessResult:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyTrait:: |
|
AccessResult:: |
public | function | Inherits the cacheability of the other access result, if any. | |
AccessResult:: |
public | function |
Overrides AccessResultInterface:: |
1 |
AccessResult:: |
public | function |
Overrides AccessResultInterface:: |
1 |
AccessResult:: |
public | function |
Overrides AccessResultInterface:: |
1 |
AccessResult:: |
public static | function | Creates an AccessResultInterface object with isNeutral() === TRUE. | |
AccessResult:: |
public | function |
Combine this access result with another using OR. Overrides AccessResultInterface:: |
|
AccessResult:: |
public | function | Resets cache contexts (to the empty array). | |
AccessResult:: |
public | function | Resets cache tags (to the empty array). | |
AccessResult:: |
public | function | Sets the maximum age for which this access result may be cached. | |
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
GroupAccessResult:: |
public static | function | Allows access if the permission is present, neutral otherwise. | |
GroupAccessResult:: |
public static | function | Allows access if the permissions are present, neutral otherwise. | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function |