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.
What would the best way be to make the cnr items display at the front of the list instead of the end? The key line is:
$referenced_node->{$away_field}[$referenced_node->language][] = array('nid' => $home_node->nid);
I'd like a way of controlling that so that it worked as follows:
if ($crazy_logic) {
array_unshift($referenced_node->{$away_field}[$referenced_node->language], array('nid' => $home_node->nid));
}
else {
$referenced_node->{$away_field}[$referenced_node->language][] = array('nid' => $home_node->nid);
}
The question is, what would the best way be to encapsulate this logic? :)
Comment | File | Size | Author |
---|---|---|---|
#2 | cnr-n1512614-2-d7.patch | 1.27 KB | DamienMcKenna |
#1 | cnr-n1512614-d7.patch | 1.21 KB | DamienMcKenna |
Comments
Comment #1
DamienMcKennaThis allows for a variable in the format "cnr*{$away_node_type}*{$away_field}*{$home_node->type}*{$home_field}*forwards", that defaults to TRUE; if this variable is set to FALSE then new items will be added to the front of the list instead of the end.
Obviously implementing a UX to control this would be a little complex, I used it as follows:
Comment #2
DamienMcKennaThe patch & code in #1 did't take into consideration the node ID. Doh. Replace this code as above:
and:
The only part that changed was the $var_name variable.