This may be a more general thing, but if it is I haven't been able to find the right issue: using EntityFieldQuery.
If I have
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->propertyCondition('status', 1)
->propertyCondition('type', array('blog'))
->fieldOrderBy('field_date', 'value', 'desc')
->execute();
It works nicely, but for administrators, at least, it doesn't respect domain access settings.
If I use addTag('node_access') it crashes out with "PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_field_date0.nid' in 'on clause':" etc.
If I remove fieldOrderBy, but keep addTag('node_access') it works and respects domain access settings.
If I try it without Domain Access, but with fieldOrderBy and addTag, it seems to work.
I tried adding
hook_query_entity_field_access_alter(QueryAlterableInterface $query) {
domain_alter_node_query($query, 'node');
}
and that crashes out with the same PDO error.
Comments
Comment #1
apemantus commented(The workaround seems to be to avoid EFQ and use db_select instead, which requires a bit more hard work, but doesn't seem to crap out on node_access)
Comment #2
agentrickardThis is a problem only for admins, and it may be that domain_alter_node_query() hasn't kept pace with changes to core EFQ.
What version of Drupal core are you running?
Comment #3
agentrickardIn your pseudo-code from #1, the second argument should be "entity", not "node".
Comment #4
agentrickardIn the fieldOrderBy(), did you try using the field name without the _field prefix? e.g. This fails for me on core:
But this works:
Comment #5
agentrickardHm. Even using "body" the local domain_query function throws an error.
Comment #6
agentrickardI looked harder at the code in node module, and there are two things here:
1) Your query actually needs to be tagged with "entity_field_access" not "node_access". This is unclear in the documentation, but clear in the comments in node_query_entity_access_alter().
2) DA needs to add the new hook to account for EFQ.
Comment #7
agentrickardAdding support for EFQ is a feature.
Comment #8
agentrickardHere's a patch for testing. As far as I call tell, the 'entity_field_access' tag is added to all EFQ queries.
Comment #9
agentrickardNeeds a re-roll in light of #1889356: Performance impact with domain access: Is SELECT DISTINCT really necessary on every sql rewrite?
Comment #10
redsky commented+1 for this feature request.
Comment #11
DeFr commentedNeeded that for a project I'm working on, so re-rerolled the patch.
As far as I can tell, all the cleanup that went into the other issue made this one really straightforward, so attaching matching patch.
Comment #12
bluegeek9 commentedDrupal 7 in End of Life and no longer supported. We encourage you to upgrade to a supported version of Drupal. For more information, see https://www.drupal.org/upgrade.