Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / src / DateFormatAccessControlHandler.php
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 function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
21     // There are no restrictions on viewing a date format.
22     if ($operation == 'view') {
23       return AccessResult::allowed();
24     }
25     // Locked date formats cannot be updated or deleted.
26     elseif (in_array($operation, ['update', 'delete'])) {
27       if ($entity->isLocked()) {
28         return AccessResult::forbidden()->addCacheableDependency($entity);
29       }
30       else {
31         return parent::checkAccess($entity, $operation, $account)->addCacheableDependency($entity);
32       }
33     }
34
35     return parent::checkAccess($entity, $operation, $account);
36   }
37
38 }