Version 1
[yaffs-website] / web / core / modules / search / src / SearchPageAccessControlHandler.php
1 <?php
2
3 namespace Drupal\search;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Access\AccessibleInterface;
7 use Drupal\Core\Entity\EntityAccessControlHandler;
8 use Drupal\Core\Entity\EntityInterface;
9 use Drupal\Core\Session\AccountInterface;
10
11 /**
12  * Defines the access control handler for the search page entity type.
13  *
14  * @see \Drupal\search\Entity\SearchPage
15  */
16 class SearchPageAccessControlHandler extends EntityAccessControlHandler {
17
18   /**
19    * {@inheritdoc}
20    */
21   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
22     /** @var $entity \Drupal\search\SearchPageInterface */
23     if (in_array($operation, ['delete', 'disable'])) {
24       if ($entity->isDefaultSearch()) {
25         return AccessResult::forbidden()->addCacheableDependency($entity);
26       }
27       else {
28         return parent::checkAccess($entity, $operation, $account)->addCacheableDependency($entity);
29       }
30     }
31     if ($operation == 'view') {
32       if (!$entity->status()) {
33         return AccessResult::forbidden()->addCacheableDependency($entity);
34       }
35       $plugin = $entity->getPlugin();
36       if ($plugin instanceof AccessibleInterface) {
37         return $plugin->access($operation, $account, TRUE)->addCacheableDependency($entity);
38       }
39       return AccessResult::allowed()->addCacheableDependency($entity);
40     }
41     return parent::checkAccess($entity, $operation, $account);
42   }
43
44 }