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

apemantus’s picture

Priority: Normal » Minor

(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)

agentrickard’s picture

This 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?

agentrickard’s picture

In your pseudo-code from #1, the second argument should be "entity", not "node".

agentrickard’s picture

Category: bug » support

In the fieldOrderBy(), did you try using the field name without the _field prefix? e.g. This fails for me on core:

  $query = new EntityFieldQuery();
  $result = $query->entityCondition('entity_type', 'node')
  ->propertyCondition('status', 1)
  ->propertyCondition('type', array('article'))
  ->fieldOrderBy('field_data_body', 'value', 'desc')
  ->execute();

But this works:

  $query = new EntityFieldQuery();
  $result = $query->entityCondition('entity_type', 'node')
  ->propertyCondition('status', 1)
  ->propertyCondition('type', array('article'))
  ->fieldOrderBy('body', 'value', 'desc')
  ->execute();
agentrickard’s picture

Category: support » bug

Hm. Even using "body" the local domain_query function throws an error.

agentrickard’s picture

I 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.

agentrickard’s picture

Category: bug » feature

Adding support for EFQ is a feature.

agentrickard’s picture

Status: Active » Needs review
StatusFileSize
new5.14 KB

Here's a patch for testing. As far as I call tell, the 'entity_field_access' tag is added to all EFQ queries.

agentrickard’s picture

redsky’s picture

Issue summary: View changes

+1 for this feature request.

DeFr’s picture

Version: 7.x-3.4 » 7.x-3.x-dev
Status: Needs work » Needs review
StatusFileSize
new579 bytes

Needed 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.

bluegeek9’s picture

Status: Needs review » Closed (outdated)

Drupal 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.

//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support of this project makes other volunteer contributions more sustainable.
There are multiple ways to show appreciation for the work contributed to this project, including:
  • Triaging issues and adding more context to existing issues.
  • Writing documentation or patches for this project.