You are here

public function QueryAccessSubscriber::onGenericQueryAccess in Entity API 8

Modifies the access conditions based on the entity type.

This is just a convenient example for testing the catch-all event. A real subscriber would probably extend the conditions based on the third party settings it set on the entity type(s).

Parameters

\Drupal\entity\QueryAccess\QueryAccessEvent $event: The event.

File

tests/modules/entity_module_test/src/EventSubscriber/QueryAccessSubscriber.php, line 33

Class

QueryAccessSubscriber

Namespace

Drupal\entity_module_test\EventSubscriber

Code

public function onGenericQueryAccess(QueryAccessEvent $event) {
  $conditions = $event
    ->getConditions();
  $email = $event
    ->getAccount()
    ->getEmail();
  if ($event
    ->getEntityTypeId() == 'entity_test_enhanced_with_owner') {

    // Disallow access to entity_test_enhanced_with_owner for the user with
    // email address user9000@example.com. Anyone else has access.
    if ($email == 'user9000@example.com') {
      $conditions
        ->alwaysFalse();
    }
    elseif ($email == 'user9001@example.com') {
      $conditions
        ->alwaysFalse(FALSE);
    }
  }
}