When I use contextual filters in a view, I can select an option to display a summary when the argument is not present. If I do it, it shows a list of node IDs instead of titles. For example, I get the following output, where the first number is the node ID, and the second number is the count of nodes.
- 1256 (12)
- 4323 (723)
- 5643 (34)
I want is to rewrite the output and replace the node ID with its title. ViewExecutable
has a $args
property I can check to know when the argument is not present.
How could I achieve this in a hook? In Drupal 7 I could use hook_views_post_execute()
. I modified $view->result
and changed it on my own.
I tried to do the same with Drupal 8 and the same hook, but hook_views_pre_render()
gets a ViewExecutable
object, and I don’t know how to change it. I used the following code.
function MYMODULE_views_pre_render(ViewExecutable $view) { if ($view->id() == 'myidoftheview') { $results = $view->result; foreach ($results as $result) { Drupal::logger('myview')->notice('<pre>'.print_r($result,TRUE).'</pre>'); // What code should I write here? } } }