EventOnlyQueryAccessHandler.php in Entity API 8
File
src/QueryAccess/EventOnlyQueryAccessHandler.php
View source
<?php
namespace Drupal\entity\QueryAccess;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
final class EventOnlyQueryAccessHandler implements EntityHandlerInterface, QueryAccessHandlerInterface {
protected $entityType;
protected $eventDispatcher;
protected $currentUser;
public function __construct(EntityTypeInterface $entity_type, EventDispatcherInterface $event_dispatcher, AccountInterface $current_user) {
$this->entityType = $entity_type;
$this->eventDispatcher = $event_dispatcher;
$this->currentUser = $current_user;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('event_dispatcher'), $container
->get('current_user'));
}
public function getConditions($operation, AccountInterface $account = NULL) {
$account = $account ?: $this->currentUser;
$entity_type_id = $this->entityType
->id();
$conditions = new ConditionGroup('OR');
$event = new QueryAccessEvent($conditions, $operation, $account, $entity_type_id);
$this->eventDispatcher
->dispatch("entity.query_access", $event);
$this->eventDispatcher
->dispatch("entity.query_access.{$entity_type_id}", $event);
return $conditions;
}
}