SmartDateFormatAccessControlHandler.php in Smart Date 3.0.x
Same filename and directory in other branches
- 8.2 src/Entity/SmartDateFormatAccessControlHandler.php
- 8 src/Entity/SmartDateFormatAccessControlHandler.php
- 3.x src/Entity/SmartDateFormatAccessControlHandler.php
- 3.1.x src/Entity/SmartDateFormatAccessControlHandler.php
- 3.2.x src/Entity/SmartDateFormatAccessControlHandler.php
- 3.3.x src/Entity/SmartDateFormatAccessControlHandler.php
- 3.4.x src/Entity/SmartDateFormatAccessControlHandler.php
Namespace
Drupal\smart_date\EntityFile
src/Entity/SmartDateFormatAccessControlHandler.phpView source
<?php
namespace Drupal\smart_date\Entity;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Defines the access control handler for the smart date format entity type.
*
* @see \Drupal\smart_date\Entity\SmartDateFormat
*/
class SmartDateFormatAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected $viewLabelOperation = TRUE;
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
// There are no restrictions on viewing the label of a date format.
if ($operation === 'view label') {
return AccessResult::allowed();
}
elseif (in_array($operation, [
'delete',
])) {
if ($entity
->label() == 'default') {
return AccessResult::forbidden('The SmartDateFormat config entity cannot be deleted.')
->addCacheableDependency($entity);
}
else {
return parent::checkAccess($entity, $operation, $account)
->addCacheableDependency($entity);
}
}
return parent::checkAccess($entity, $operation, $account);
}
}
Classes
Name | Description |
---|---|
SmartDateFormatAccessControlHandler | Defines the access control handler for the smart date format entity type. |