Completed
Pull Request — 8.x-1.x (#130)
by
unknown
11:37
created

checkCreateAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/**
4
 * @file
5
 * Contains \Drupal\entity_browser\EntityBrowserAccessControlHandler
6
 */
7
8
namespace Drupal\entity_browser;
9
10
use Drupal\Core\Access\AccessResult;
11
use Drupal\Core\Entity\EntityAccessControlHandler;
12
use Drupal\Core\Entity\EntityInterface;
13
use Drupal\Core\Session\AccountInterface;
14
15
/**
16
 * Access controller for the entity browser.
17
 *
18
 */
19
class EntityBrowserAccessControlHandler extends EntityAccessControlHandler {
20
21
  /**
22
   * {@inheritdoc}
23
   *
24
   * Link the activities to the permissions. checkAccess is called with the
25
   * $operation as defined in the routing.yml file.
26
   */
27
  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
28
    switch ($operation) {
29
      case 'view':
30
        return AccessResult::allowedIfHasPermission($account, 'administer entity browsers');
31
32
      case 'edit':
33
        return AccessResult::allowedIfHasPermission($account, 'administer entity browsers');
34
35
      case 'delete':
36
        return AccessResult::allowedIfHasPermission($account, 'administer entity browsers');
37
    }
38
    return AccessResult::allowed();
39
  }
40
41
  /**
42
   * {@inheritdoc}
43
   *
44
   * Separate from the checkAccess because the entity does not yet exist, it
45
   * will be created during the 'add' process.
46
   */
47
  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
48
    return AccessResult::allowedIfHasPermission($account, 'administer entity browsers');
49
  }
50
51
}
52