entity_activity-8.x-1.0-beta13/src/Access/SubscriptionAccessCheck.php
src/Access/SubscriptionAccessCheck.php
<?php
namespace Drupal\entity_activity\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
/**
* Access check for the subscription api.
*
* Check if a user can (un)subscribe on a content entity.
*/
class SubscriptionAccessCheck implements AccessInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new SubscriptionAccessCheck object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* Checks access.
*
* More advanced access checks are done by the API itself.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
if ($account->isAnonymous()) {
return AccessResult::forbidden('Anonymous can not subscribe on entities')
->cachePerPermissions();
}
if ($account->hasPermission('subscribe all entities')) {
return AccessResult::allowed()
->cachePerPermissions();
}
return AccessResult::forbidden('Forbidden by default.')
->cachePerPermissions();
}
}
