3 namespace Drupal\shortcut;
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityAccessControlHandler;
7 use Drupal\Core\Entity\EntityHandlerInterface;
8 use Drupal\Core\Entity\EntityInterface;
9 use Drupal\Core\Entity\EntityTypeInterface;
10 use Drupal\Core\Session\AccountInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * Defines the access control handler for the shortcut entity type.
16 * @see \Drupal\shortcut\Entity\Shortcut
18 class ShortcutAccessControlHandler extends EntityAccessControlHandler implements EntityHandlerInterface {
21 * The shortcut_set storage.
23 * @var \Drupal\shortcut\ShortcutSetStorageInterface
25 protected $shortcutSetStorage;
28 * Constructs a ShortcutAccessControlHandler object.
30 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
31 * The entity type definition.
32 * @param \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage
33 * The shortcut_set storage.
35 public function __construct(EntityTypeInterface $entity_type, ShortcutSetStorageInterface $shortcut_set_storage) {
36 parent::__construct($entity_type);
37 $this->shortcutSetStorage = $shortcut_set_storage;
43 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
46 $container->get('entity.manager')->getStorage('shortcut_set')
53 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
54 if ($shortcut_set = $this->shortcutSetStorage->load($entity->bundle())) {
55 return shortcut_set_edit_access($shortcut_set, $account);
57 // @todo Fix this bizarre code: how can a shortcut exist without a shortcut
58 // set? The above if-test is unnecessary. See https://www.drupal.org/node/2339903.
59 return AccessResult::neutral()->addCacheableDependency($entity);
65 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
66 if ($shortcut_set = $this->shortcutSetStorage->load($entity_bundle)) {
67 return shortcut_set_edit_access($shortcut_set, $account);
69 // @todo Fix this bizarre code: how can a shortcut exist without a shortcut
70 // set? The above if-test is unnecessary. See https://www.drupal.org/node/2339903.
71 return AccessResult::neutral();