I'm using the EntityFieldQuery API to query a series of nodes for a specific domain. I then use node_load_multiple().
When looking at the results I noticed that all the nodes in the resulting array had the domain_source property of the node object set to the same value when in fact the nodes should have different domain_source values.
The problem seems to be something to do node_load_multiple() using the entiry_load() method instead of node_load(). I wrote my own function the iterates over the EntityFieldQuery results and returns the node objects using node_load(). The resulting array this time has the correct domain_source values.
Here is a example of the code using node_load_multiple():
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'page')
->propertyCondition('status', 1, '=')
->execute();
$nodes = node_load_multiple(array_keys($result['node']));
kpr($nodes)
exit;
You'll need to install/enable the devel to use the kpr() function.
Here is my workaround that returns the correct domain_source values:
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'page')
->propertyCondition('status', 1, '=')
->execute();
$nids = node_load_multiple(array_keys($result['node']));
$nodes = array();
foreach($nids as $nid) {
$nodes[] = node_load($nid);
}
kpr($nodes)
exit;
I'm not sure if the bug is to do with the Domain Access module or a bug in Drupal core.
Comment | File | Size | Author |
---|---|---|---|
#5 | 1219746-static-reset.patch | 1.3 KB | agentrickard |
Comments
Comment #1
agentrickardHm. Domain Source data isn't stored by FieldAPI, so I wonder what's going on here.
We've have problems with statics / loads in the past (you could search closed issues).
Does it matter if you do this:
Also note that in the query sample here, there is no need for EFQ, since 'bundle' is analogous to {node}.type.
Comment #2
agentrickardComment #3
agentrickardComment #4
agentrickardFound the problem. See #1307914: Document that the hook_entity_load() and hook_ENTITY_TYPE_load() functions should never have their own static caches.
Retitling issue as a general cleanup. This is now a release blocker.
Comment #5
agentrickardStart at a patch. Needs more work and lots of test.