comparison core/modules/shortcut/src/ShortcutSetAccessControlHandler.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\shortcut;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Entity\EntityAccessControlHandler;
8 use Drupal\Core\Session\AccountInterface;
9
10 /**
11 * Defines the access control handler for the shortcut set entity type.
12 *
13 * @see \Drupal\shortcut\Entity\ShortcutSet
14 */
15 class ShortcutSetAccessControlHandler extends EntityAccessControlHandler {
16
17 /**
18 * {@inheritdoc}
19 */
20 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
21 switch ($operation) {
22 case 'view':
23 return AccessResult::allowedIf($account->hasPermission('access shortcuts'))->cachePerPermissions();
24 case 'update':
25 if ($account->hasPermission('administer shortcuts')) {
26 return AccessResult::allowed()->cachePerPermissions();
27 }
28 if (!$account->hasPermission('access shortcuts')) {
29 return AccessResult::neutral()->cachePerPermissions();
30 }
31 return AccessResult::allowedIf($account->hasPermission('customize shortcut links') && $entity == shortcut_current_displayed_set($account))->cachePerPermissions()->addCacheableDependency($entity);
32
33 case 'delete':
34 return AccessResult::allowedIf($account->hasPermission('administer shortcuts') && $entity->id() != 'default')->cachePerPermissions();
35
36 default:
37 // No opinion.
38 return AccessResult::neutral();
39 }
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
46 return AccessResult::allowedIfHasPermission($account, 'administer shortcuts')->orIf(AccessResult::allowedIfHasPermissions($account, ['access shortcuts', 'customize shortcut links'], 'AND'));
47 }
48
49 }