comparison core/modules/taxonomy/src/TermAccessControlHandler.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\taxonomy;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityAccessControlHandler;
7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Session\AccountInterface;
9
10 /**
11 * Defines the access control handler for the taxonomy term entity type.
12 *
13 * @see \Drupal\taxonomy\Entity\Term
14 */
15 class TermAccessControlHandler 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::allowedIfHasPermission($account, 'access content');
24
25 case 'update':
26 return AccessResult::allowedIfHasPermissions($account, ["edit terms in {$entity->bundle()}", 'administer taxonomy'], 'OR');
27
28 case 'delete':
29 return AccessResult::allowedIfHasPermissions($account, ["delete terms in {$entity->bundle()}", 'administer taxonomy'], 'OR');
30
31 default:
32 // No opinion.
33 return AccessResult::neutral();
34 }
35 }
36
37 /**
38 * {@inheritdoc}
39 */
40 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
41 return AccessResult::allowedIfHasPermission($account, 'administer taxonomy');
42 }
43
44 }