public function EntityFlagType::actionAccess in Flag 8.4
Checks whether a user has permission to flag/unflag or not.
Parameters
string $action: The action for which to check permissions, either 'flag' or 'unflag'.
\Drupal\flag\FlagInterface $flag: The flag object.
\Drupal\Core\Session\AccountInterface $account: An AccountInterface object.
\Drupal\Core\Entity\EntityInterface $flaggable: (optional) The flaggable entity.
Return value
\Drupal\Core\Access\AccessResult An AccessResult object.
Overrides FlagTypeBase::actionAccess
1 call to EntityFlagType::actionAccess()
- UserFlagType::actionAccess in src/
Plugin/ Flag/ UserFlagType.php - Checks whether a user has permission to flag/unflag or not.
3 methods override EntityFlagType::actionAccess()
- AccessDenied::actionAccess in tests/
modules/ flag_test_plugins/ src/ Plugin/ Flag/ AccessDenied.php - Checks whether a user has permission to flag/unflag or not.
- AccessGranted::actionAccess in tests/
modules/ flag_test_plugins/ src/ Plugin/ Flag/ AccessGranted.php - Checks whether a user has permission to flag/unflag or not.
- UserFlagType::actionAccess in src/
Plugin/ Flag/ UserFlagType.php - Checks whether a user has permission to flag/unflag or not.
File
- src/
Plugin/ Flag/ EntityFlagType.php, line 314
Class
- EntityFlagType
- Provides a flag type for all entity types.
Namespace
Drupal\flag\Plugin\FlagCode
public function actionAccess($action, FlagInterface $flag, AccountInterface $account, EntityInterface $flaggable = NULL) {
$access = parent::actionAccess($action, $flag, $account, $flaggable);
if ($flaggable instanceof EntityOwnerInterface && $this
->hasExtraPermission('owner')) {
// Own items.
$permission = $action . ' ' . $flag
->id() . ' own items';
$own_permission_access = AccessResult::allowedIfHasPermission($account, $permission)
->addCacheContexts([
'user',
]);
$account_match_access = AccessResult::allowedIf($account
->id() == $flaggable
->getOwnerId());
$own_access = $own_permission_access
->andIf($account_match_access);
$access = $access
->orIf($own_access);
// Others' items.
$permission = $action . ' ' . $flag
->id() . ' other items';
$others_permission_access = AccessResult::allowedIfHasPermission($account, $permission)
->addCacheContexts([
'user',
]);
$account_mismatch_access = AccessResult::allowedIf($account
->id() != $flaggable
->getOwnerId());
$others_access = $others_permission_access
->andIf($account_mismatch_access);
$access = $access
->orIf($others_access);
}
return $access;
}