Newer
Older
Alex Pott
committed
<?php
namespace Drupal\system;
catch
committed
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
Alex Pott
committed
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Defines the access control handler for the date format entity type.
*
* @see \Drupal\system\Entity\DateFormat
Alex Pott
committed
*/
class DateFormatAccessControlHandler extends EntityAccessControlHandler {
Alex Pott
committed
/**
* {@inheritdoc}
*/
protected $viewLabelOperation = TRUE;
Alex Pott
committed
/**
* {@inheritdoc}
*/
Alex Bronstein
committed
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
// There are no restrictions on viewing the label of a date format.
if ($operation === 'view label') {
catch
committed
return AccessResult::allowed();
Alex Pott
committed
}
// Locked date formats cannot be updated or deleted.
elseif (in_array($operation, ['update', 'delete'])) {
catch
committed
if ($entity->isLocked()) {
return AccessResult::forbidden('The DateFormat config entity is locked.')->addCacheableDependency($entity);
catch
committed
}
else {
return parent::checkAccess($entity, $operation, $account)->addCacheableDependency($entity);
catch
committed
}
Alex Pott
committed
}
Alex Bronstein
committed
return parent::checkAccess($entity, $operation, $account);