3 namespace Drupal\filter;
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 filter format entity type.
13 * @see \Drupal\filter\Entity\FilterFormat
15 class FilterFormatAccessControlHandler extends EntityAccessControlHandler {
20 protected function checkAccess(EntityInterface $filter_format, $operation, AccountInterface $account) {
21 /** @var \Drupal\filter\FilterFormatInterface $filter_format */
23 // All users are allowed to use the fallback filter.
24 if ($operation == 'use') {
25 if ($filter_format->isFallbackFormat()) {
26 return AccessResult::allowed();
29 return AccessResult::allowedIfHasPermission($account, $filter_format->getPermissionName());
33 // The fallback format may not be disabled.
34 if ($operation == 'disable' && $filter_format->isFallbackFormat()) {
35 return AccessResult::forbidden();
38 // We do not allow filter formats to be deleted through the UI, because that
39 // would render any content that uses them unusable.
40 if ($operation == 'delete') {
41 return AccessResult::forbidden();
44 if (in_array($operation, ['disable', 'update', 'view'])) {
45 return parent::checkAccess($filter_format, $operation, $account);
49 return AccessResult::neutral();