class ProfileAccessCheck in Profile 2 8
Checks access to add, edit and delete profiles.
Hierarchy
- class \Drupal\profile\Access\ProfileAccessCheck implements AccessCheckInterface
Expanded class hierarchy of ProfileAccessCheck
1 string reference to 'ProfileAccessCheck'
1 service uses ProfileAccessCheck
File
- src/
Access/ ProfileAccessCheck.php, line 23 - Contains \Drupal\profile\Access\ProfileAccessCheck.
Namespace
Drupal\profile\AccessView source
class ProfileAccessCheck implements AccessCheckInterface {
/**
* A user account to check access for.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Service RequestStack
* @var RequestStack
*/
protected $requestStack;
/**
* Constructs a EntityCreateAccessCheck object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request stack.
*/
public function __construct(EntityManagerInterface $entity_manager, RequestStack $requestStack) {
$this->entityManager = $entity_manager;
$this->requestStack = $requestStack;
}
/**
* Implements AccessCheckInterface::applies().
*/
public function applies(Route $route) {
return FALSE;
}
public function access(AccountInterface $account, ProfileTypeInterface $profile_type = NULL) {
$access_control_handler = $this->entityManager
->getAccessControlHandler('profile');
$operation = $this->requestStack
->getCurrentRequest()->attributes
->get('operation');
if ($operation == 'add') {
return $access_control_handler
->access($profile_type, $operation, LanguageInterface::LANGCODE_DEFAULT, $account, TRUE);
}
// If checking whether a profile of a particular type may be created.
if ($profile_type) {
return $access_control_handler
->createAccess($profile_type
->id(), $account, [], TRUE);
}
// If checking whether a profile of any type may be created.
foreach ($this->entityManager
->getStorage('profile_type')
->loadMultiple() as $profile_type) {
if (($access = $access_control_handler
->createAccess($profile_type
->id(), $account, [], TRUE)) && $access
->isAllowed()) {
return $access;
}
}
// No opinion.
return AccessResult::neutral();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProfileAccessCheck:: |
protected | property | A user account to check access for. | |
ProfileAccessCheck:: |
protected | property | The entity manager. | |
ProfileAccessCheck:: |
protected | property | Service RequestStack | |
ProfileAccessCheck:: |
public | function | ||
ProfileAccessCheck:: |
public | function |
Implements AccessCheckInterface::applies(). Overrides AccessCheckInterface:: |
|
ProfileAccessCheck:: |
public | function | Constructs a EntityCreateAccessCheck object. |