Hi,
I am trying to get all nodes in an update hook.

$query              = \Drupal::entityQuery('node')
      ->condition('type', 'basic_article_page');
    $nids               = $query->execute();

is giving me only nids to a specific domain.
Maybe this is accidentally because those nodes are also the only one in "en" language code.
I can make it work when I put it in a MYMODULE_node_view hook but not in a MYMODULE_update_n hook.
Am I doing something wrong?
Greetings
Lars

Comments

Synflag created an issue. See original summary.

Synflag’s picture

Title: How to limit anentityQuery NOT to a domain » How to limit an entityQuery NOT to a domain
agentrickard’s picture

By default, any EntityQuery or EntityField query is tagged with an entity access check which prevents displaying entities that should be restricted. This is a security feature and should not normally be bypassed.

If you are writing queries for an administrative interface, you can bypass that access check like so:

$query = \Drupal::entityQuery('node')
  ->condition('type', 'basic_article_page')
  ->accessCheck(FALSE);

If using Views, you would check the Advanced option 'Disable SQL rewrites.'

This code may also need to be changed in DomainContentController::getCount(), since in earlier versions of Drupal that access tag had to be added manually.

See https://www.drupal.org/node/1597378 and https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...

agentrickard’s picture

I hadn't noticed that code change until now, and there is an error in the controller.

  • agentrickard committed c2780fb on 8.x-1.x
    Issue #2931438 by Synflag, agentrickard: How to limit an entityQuery NOT...
agentrickard’s picture

Status: Active » Fixed

Committed. Thanks for the report!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.