3 namespace Drupal\system;
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityAccessControlHandler;
7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Session\AccountInterface;
11 * Defines the access control handler for the date format entity type.
13 * @see \Drupal\system\Entity\DateFormat
15 class DateFormatAccessControlHandler extends EntityAccessControlHandler {
20 protected $viewLabelOperation = TRUE;
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();
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);
36 return parent::checkAccess($entity, $operation, $account)->addCacheableDependency($entity);
40 return parent::checkAccess($entity, $operation, $account);