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.
Hello!
I've been trying to modify a bit of code for a custom module that allows me to insert a custom row into a view. I'm using a taxonomy view, and the custom row needs to link to a node instead of a taxonomy term. The module I'd been working with was created just for node views and was built to customize an existing array of fields; I'm trying to insert a custom link to a particular node, but since node fields aren't available in a taxonomy view, I'm not really sure what the best option would be.
Any suggestions?
This is the code I would like to modify:
function modulename_views_post_execute(&$view) {
// wait for the right view
if($view->name == "menu_views_taxonomy_" && $view->current_display == "block_1") {
// create the object you want to insert in the result
$temp = new stdClass;
// node title
$temp->node_title = "View All"; //This field doesn't exist in the taxonomy view
// nodeID
$temp->nid = 97; //This field also doesn't exist in the taxonomy view
$new_result_array = array();
$i = 0;
foreach($view->result as $single_result) {
if($i == 0) {
// insert the extra node at 1st position
$new_result_array[] = $temp;
$new_result_array[] = $single_result;
} else {
$new_result_array[] = $single_result;
}
$i++;
}
// replace the old result array
$view->result = $new_result_array;
}
}
Thanks!
Comments
Comment #1
MustangGB CreditAttribution: MustangGB commented