Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / filter / src / FilterFormatAccessControlHandler.php
1 <?php
2
3 namespace Drupal\filter;
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 filter format entity type.
12  *
13  * @see \Drupal\filter\Entity\FilterFormat
14  */
15 class FilterFormatAccessControlHandler extends EntityAccessControlHandler {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function checkAccess(EntityInterface $filter_format, $operation, AccountInterface $account) {
21     /** @var \Drupal\filter\FilterFormatInterface $filter_format */
22
23     // All users are allowed to use the fallback filter.
24     if ($operation == 'use') {
25       if ($filter_format->isFallbackFormat()) {
26         return AccessResult::allowed();
27       }
28       else {
29         return AccessResult::allowedIfHasPermission($account, $filter_format->getPermissionName());
30       }
31     }
32
33     // The fallback format may not be disabled.
34     if ($operation == 'disable' && $filter_format->isFallbackFormat()) {
35       return AccessResult::forbidden();
36     }
37
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();
42     }
43
44     if (in_array($operation, ['disable', 'update', 'view'])) {
45       return parent::checkAccess($filter_format, $operation, $account);
46     }
47
48     // No opinion.
49     return AccessResult::neutral();
50   }
51
52 }