Skip to content
Snippets Groups Projects
Select Git revision
  • 0f3735800384b8e2257c72a02b30b1cbe7371b95
  • 11.x default protected
  • 10.6.x protected
  • 10.5.x protected
  • 11.2.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

forum.module

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    EntityAccessControlHandler.php 13.58 KiB
    <?php
    
    namespace Drupal\Core\Entity;
    
    use Drupal\Core\Access\AccessResult;
    use Drupal\Core\Field\FieldItemListInterface;
    use Drupal\Core\Field\FieldDefinitionInterface;
    use Drupal\Core\Language\LanguageInterface;
    use Drupal\Core\Session\AccountInterface;
    
    /**
     * Defines a default implementation for entity access control handler.
     */
    class EntityAccessControlHandler extends EntityHandlerBase implements EntityAccessControlHandlerInterface {
    
      /**
       * Stores calculated access check results.
       *
       * @var array
       */
      protected $accessCache = [];
    
      /**
       * The entity type ID of the access control handler instance.
       *
       * @var string
       */
      protected $entityTypeId;
    
      /**
       * Information about the entity type.
       *
       * @var \Drupal\Core\Entity\EntityTypeInterface
       */
      protected $entityType;
    
      /**
       * Allows to grant access to just the labels.
       *
       * By default, the "view label" operation falls back to "view". Set this to
       * TRUE to allow returning different access when just listing entity labels.
       *
       * @var bool
       */
      protected $viewLabelOperation = FALSE;
    
      /**
       * Constructs an access control handler instance.
       *
       * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
       *   The entity type definition.
       */
      public function __construct(EntityTypeInterface $entity_type) {
        $this->entityTypeId = $entity_type->id();
        $this->entityType = $entity_type;
      }
    
      /**
       * {@inheritdoc}
       */
      public function access(EntityInterface $entity, $operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
        $account = $this->prepareUser($account);
        $langcode = $entity->language()->getId();
    
        if ($operation === 'view label' && $this->viewLabelOperation == FALSE) {
          $operation = 'view';
        }
    
        if (($return = $this->getCache($entity->uuid(), $operation, $langcode, $account)) !== NULL) {
          // Cache hit, no work necessary.