ShortcutAccessController.php 1.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
<?php

/**
 * @file
 * Contains \Drupal\shortcut\ShortcutAccessController.
 */

namespace Drupal\shortcut;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityAccessController;
12
use Drupal\Core\Session\AccountInterface;
13
14
15
16
17
18
19
20
21

/**
 * Defines the access controller for the shortcut entity type.
 */
class ShortcutAccessController extends EntityAccessController {

  /**
   * {@inheritdoc}
   */
22
  protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
23
    switch ($operation) {
24
      case 'create':
25
      case 'update':
26
27
28
29
30
31
        if (user_access('administer shortcuts', $account)) {
          return TRUE;
        }
        if (user_access('customize shortcut links', $account)) {
          return !isset($entity) || $entity == shortcut_current_displayed_set($account);
        }
32
        return FALSE;
33
34
35
36
37
38
39
        break;
      case 'delete':
        if (!user_access('administer shortcuts', $account)) {
          return FALSE;
        }
        return $entity->id() != 'default';
        break;
40
41
    }
  }
42

43
}