"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/search/src/SearchPageAccessControlHandler.php" (26 Nov 2020, 1425 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "SearchPageAccessControlHandler.php" see the Fossies "Dox" file reference documentation.

    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 }