Found a pretty basic bug with nodequeue that is causing a lot of errors on our site.
To replicate:
- Use a fresh Drupal 7 install.
- Install nodequeue
- Create a nodequeue, and assign 3 basic pages to the nodequeue
- Edit themes/bartik/template.php, and add the following code into bartik_preprocess_html
$nodes = nodequeue_view_nodes(1, FALSE);
You can place this code anywhere else, a module or whatever, the outcome is the same. I get errors:
Notice: Undefined offset: 3 in _field_invoke_multiple() (line 328 of /Users/thomaswilhelm/Sites/drupal-7.38/modules/field/field.attach.inc).
This is caused by the nodequeue_load_nodes() function, this returns nodes indexed 0,1,2,3 etc. due to the following lines:
// Return numerically indexed array for backward compatibility.
// @todo reevaluate this.
return array_values(node_load_multiple($result));
changing this to:
return node_load_multiple($result);
Fixes the error for me.
This I believe is because node_view_multiple() which is called in nodequeue_view_nodes() expects the $nodes array it receives to haves keys which match the node ID's of each element.
Comment | File | Size | Author |
---|---|---|---|
#3 | nodequeue_view_nodes_is-2544478-3.patch | 479 bytes | Pravin Ajaaz |
Comments
Comment #1
ThomWilhelm CreditAttribution: ThomWilhelm commentedComment #2
ThomWilhelm CreditAttribution: ThomWilhelm commentedComment #3
Pravin Ajaaz CreditAttribution: Pravin Ajaaz at Ameex-Drupal Geeks commentedHere is the patch for it
Comment #5
fizk CreditAttribution: fizk commentedThis bug was introduced in #2314177: Fix D6 style nodequeue_view_nodes() arguments. I don't see any reason why
nodequeue_load_nodes()
needs to returnarray_values(node_load_multiple($result))
, so this patch makes sense.Comment #7
jgrubb CreditAttribution: jgrubb commentedThe reason is that we (and I'm sure we're not the only ones who) had code written against the old API, which returned a 0-indexed array of nodes. Granted, the output directly from node_load_multiple() would have been better in the first place and fixes the issue with node_view_multiple(), but this change was a breaking one for code that we'd written expecting a 0-indexed array to be returned.
Comment #8
mrdemeanour CreditAttribution: mrdemeanour commentedIn the light of this API change, perhaps consider deleting this doc-comment from nodequeue_load_nodes:
* @return array
* An array of node objects (indexed sequentially, not by nid).