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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ThomWilhelm’s picture

Issue summary: View changes
ThomWilhelm’s picture

Issue summary: View changes
Pravin Ajaaz’s picture

Status: Active » Needs review
FileSize
479 bytes

Here is the patch for it

  • fizk committed dc4403a on 7.x-2.x authored by Pravin Ajaaz
    Issue #2544478 by Pravin Ajaaz: nodequeue_view_nodes is throwing notices
    
fizk’s picture

Status: Needs review » Fixed
Related issues: +#2314177: Fix D6 style nodequeue_view_nodes() arguments

This bug was introduced in #2314177: Fix D6 style nodequeue_view_nodes() arguments. I don't see any reason why nodequeue_load_nodes() needs to return array_values(node_load_multiple($result)), so this patch makes sense.

Status: Fixed » Closed (fixed)

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

jgrubb’s picture

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

mrdemeanour’s picture

In 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).