From c11daef0b5c8a2c421461dcdcbaf2f9ef5a0d6ba Mon Sep 17 00:00:00 2001 From: Kristiaan Van den Eynde Date: Mon, 29 Jun 2020 11:25:49 +0200 Subject: [PATCH] Interdiff --- entity.module | 4 ++-- ...andler.php => EventOnlyQueryAccessHandler.php} | 4 ++-- .../src/EventSubscriber/QueryAccessSubscriber.php | 8 ++++---- ...st.php => EventOnlyQueryAccessHandlerTest.php} | 15 ++++----------- 4 files changed, 12 insertions(+), 19 deletions(-) rename src/QueryAccess/{GenericQueryAccessHandler.php => EventOnlyQueryAccessHandler.php} (93%) rename tests/src/Kernel/QueryAccess/{GenericQueryAccessHandlerTest.php => EventOnlyQueryAccessHandlerTest.php} (82%) diff --git a/entity.module b/entity.module index ed55cdd..62f404e 100644 --- a/entity.module +++ b/entity.module @@ -72,10 +72,10 @@ function entity_entity_type_build(array &$entity_types) { */ function entity_entity_type_alter(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ - // Sets a generic query_access handler for all entity types that have none. + // Sets a default query_access handler for all entity types that have none. foreach ($entity_types as $entity_type_id => $entity_type) { if (!$entity_type->hasHandlerClass('query_access')) { - $entity_type->setHandlerClass('query_access', 'Drupal\entity\QueryAccess\GenericQueryAccessHandler'); + $entity_type->setHandlerClass('query_access', 'Drupal\entity\QueryAccess\EventOnlyQueryAccessHandler'); } } } diff --git a/src/QueryAccess/GenericQueryAccessHandler.php b/src/QueryAccess/EventOnlyQueryAccessHandler.php similarity index 93% rename from src/QueryAccess/GenericQueryAccessHandler.php rename to src/QueryAccess/EventOnlyQueryAccessHandler.php index db9ec79..c26b749 100644 --- a/src/QueryAccess/GenericQueryAccessHandler.php +++ b/src/QueryAccess/EventOnlyQueryAccessHandler.php @@ -15,7 +15,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; * subscribe to the query access alter event to alter any entity query or views * query without having to duplicate the related code from Entity API. */ -final class GenericQueryAccessHandler implements EntityHandlerInterface, QueryAccessHandlerInterface { +final class EventOnlyQueryAccessHandler implements EntityHandlerInterface, QueryAccessHandlerInterface { /** * The entity type. @@ -39,7 +39,7 @@ final class GenericQueryAccessHandler implements EntityHandlerInterface, QueryAc protected $currentUser; /** - * Constructs a new GenericQueryAccessHandler object. + * Constructs a new EventOnlyQueryAccessHandler object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. diff --git a/tests/modules/entity_module_test/src/EventSubscriber/QueryAccessSubscriber.php b/tests/modules/entity_module_test/src/EventSubscriber/QueryAccessSubscriber.php index 95aaa4b..a36acc1 100644 --- a/tests/modules/entity_module_test/src/EventSubscriber/QueryAccessSubscriber.php +++ b/tests/modules/entity_module_test/src/EventSubscriber/QueryAccessSubscriber.php @@ -15,7 +15,7 @@ class QueryAccessSubscriber implements EventSubscriberInterface { return [ 'entity.query_access' => 'onGenericQueryAccess', 'entity.query_access.entity_test_enhanced' => 'onQueryAccess', - 'entity.query_access.node' => 'onPolyfilledQueryAccess', + 'entity.query_access.node' => 'onEventOnlyQueryAccess', ]; } @@ -85,15 +85,15 @@ class QueryAccessSubscriber implements EventSubscriberInterface { /** * Modifies the access conditions based on the node type. * - * This is just a convenient example for testing whether the generic query + * This is just a convenient example for testing whether the event-only query * access subscriber is added to entity types that do not specify a query * access handler; in this case: node. * * @param \Drupal\entity\QueryAccess\QueryAccessEvent $event * The event. */ - public function onPolyfilledQueryAccess(QueryAccessEvent $event) { - if (\Drupal::state()->get('test_generic_query_access')) { + public function onEventOnlyQueryAccess(QueryAccessEvent $event) { + if (\Drupal::state()->get('test_event_only_query_access')) { $conditions = $event->getConditions(); $conditions->addCondition('type', 'foo'); } diff --git a/tests/src/Kernel/QueryAccess/GenericQueryAccessHandlerTest.php b/tests/src/Kernel/QueryAccess/EventOnlyQueryAccessHandlerTest.php similarity index 82% rename from tests/src/Kernel/QueryAccess/GenericQueryAccessHandlerTest.php rename to tests/src/Kernel/QueryAccess/EventOnlyQueryAccessHandlerTest.php index 857eb2e..9d75169 100644 --- a/tests/src/Kernel/QueryAccess/GenericQueryAccessHandlerTest.php +++ b/tests/src/Kernel/QueryAccess/EventOnlyQueryAccessHandlerTest.php @@ -7,17 +7,10 @@ use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; /** * Tests the generic query access handler. * - * @coversDefaultClass \Drupal\entity\QueryAccess\GenericQueryAccessHandler + * @coversDefaultClass \Drupal\entity\QueryAccess\EventOnlyQueryAccessHandler * @group entity */ -class GenericQueryAccessHandlerTest extends EntityKernelTestBase { - - /** - * The query access handler. - * - * @var \Drupal\entity\QueryAccess\QueryAccessHandler - */ - protected $handler; +class EventOnlyQueryAccessHandlerTest extends EntityKernelTestBase { /** * {@inheritdoc} @@ -42,8 +35,8 @@ class GenericQueryAccessHandlerTest extends EntityKernelTestBase { /** * Tests that entity types without a query access handler still fire events. */ - public function testGenericQueryAccessHandlerEventSubscriber() { - \Drupal::state()->set('test_generic_query_access', TRUE); + public function testEventOnlyQueryAccessHandlerEventSubscriber() { + \Drupal::state()->set('test_event_only_query_access', TRUE); $node_type_storage = $this->entityTypeManager->getStorage('node_type'); $node_type_storage->create(['type' => 'foo', 'name' => $this->randomString()])->save(); -- 2.17.1