class LogAddAccessCheck in Log entity 8
Determines access to for log add pages.
Hierarchy
- class \Drupal\log\Access\LogAddAccessCheck implements AccessInterface
Expanded class hierarchy of LogAddAccessCheck
1 string reference to 'LogAddAccessCheck'
1 service uses LogAddAccessCheck
File
- src/
Access/ LogAddAccessCheck.php, line 21 - Contains \Drupal\log\Access\LogAddAccessCheck.
Namespace
Drupal\log\AccessView source
class LogAddAccessCheck implements AccessInterface {
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a EntityCreateAccessCheck object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* Checks access to the log add page for the log type.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param \Drupal\log\LogTypeInterface $log_type
* (optional) The log type. If not specified, access is allowed if there
* exists at least one log type for which the user may create a log.
*
* @return string
* A \Drupal\Core\Access\AccessInterface constant value.
*/
public function access(AccountInterface $account, LogTypeInterface $log_type = NULL) {
$access_control_handler = $this->entityManager
->getAccessControlHandler('log');
// If checking whether a log of a particular type may be created.
if ($account
->hasPermission('administer log types')) {
return AccessResult::allowed()
->cachePerPermissions();
}
if ($log_type) {
return $access_control_handler
->createAccess($log_type
->id(), $account, [], TRUE);
}
// If checking whether a log of any type may be created.
foreach ($this->entityManager
->getStorage('log_type')
->loadMultiple() as $log_type) {
if (($access = $access_control_handler
->createAccess($log_type
->id(), $account, [], TRUE)) && $access
->isAllowed()) {
return $access;
}
}
// No opinion.
return AccessResult::neutral();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LogAddAccessCheck:: |
protected | property | The entity manager. | |
LogAddAccessCheck:: |
public | function | Checks access to the log add page for the log type. | |
LogAddAccessCheck:: |
public | function | Constructs a EntityCreateAccessCheck object. |