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