Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The function relatedcontent_get_nodes(&$node) called on a node from node.tpl.php returns the following array:
Array
(
[0] => 48
)
This is the value of the array key '48' which actually contains all the node id's, which you can see in $node->nodes like the following related content nodes:
Array
(
[48] => Array
(
[2908] => -2
[179] => -1
)
)
So to get the right values inside of key 48, I've needed to adjust the logic to:
$nodes = $node->nodes; // Keeps $node immutable.
asort($nodes, SORT_NUMERIC);
$r_nodes = array();
$keys = array_keys($nodes);
foreach($keys as $key){
$r_nodes = $nodes[$key];
}
which returns the set of related content node id's:
Array
(
[2908] => -2
[179] => -1
)
I haven't yet created a patch because I've also been messing with some other bits of the module code for customized needs.
Comments
Comment #1
adamo CreditAttribution: adamo commentedI had this problem as well. Thanks for posting this. :D One minor edit, the return line also needs to be modified which isn't shown in your snippet. This is what the full function looks like:
Just posting this clarification in case anyone else runs into this.
Comment #2
jpdaut CreditAttribution: jpdaut commentedI find I have to do this to get the node ids:
$nodes = $node->nodes;
asort($nodes, SORT_NUMERIC);
$r_nodes = array();
foreach ($nodes as $cell) {
foreach ($cell as $key => $value) {
$r_nodes[] = $key;
}
}
Comment #3
AntiNSA CreditAttribution: AntiNSA commentedCan someone make a patch of this? I would like to use this module! If nto can you tell me what exact lines to replace? Sorry Im pretty bad at the coding