comparison core/modules/system/src/DateFormatAccessControlHandler.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\system;
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 date format entity type.
12 *
13 * @see \Drupal\system\Entity\DateFormat
14 */
15 class DateFormatAccessControlHandler extends EntityAccessControlHandler {
16
17 /**
18 * {@inheritdoc}
19 */
20 protected $viewLabelOperation = TRUE;
21
22 /**
23 * {@inheritdoc}
24 */
25 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
26 // There are no restrictions on viewing the label of a date format.
27 if ($operation === 'view label') {
28 return AccessResult::allowed();
29 }
30 // Locked date formats cannot be updated or deleted.
31 elseif (in_array($operation, ['update', 'delete'])) {
32 if ($entity->isLocked()) {
33 return AccessResult::forbidden('The DateFormat config entity is locked.')->addCacheableDependency($entity);
34 }
35 else {
36 return parent::checkAccess($entity, $operation, $account)->addCacheableDependency($entity);
37 }
38 }
39
40 return parent::checkAccess($entity, $operation, $account);
41 }
42
43 }