Alter views results in a hook 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-&gt;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-&gt;id() == 'myidoftheview') {
    $results = $view-&gt;result;
    foreach ($results as $result) {
      \Drupal::logger('myview')-&gt;notice('&lt;pre&gt;'.print_r($result,TRUE).'&lt;/pre&gt;');
      // What code should I write here?
    }    
  }
}
It depends on what your result stores. It can be like entity with relation or just field:

1) $result-&gt;_entity-&gt;set('field_Name', 'xxxxxxxxxxx');

2) $value-&gt;node__field_Name = 'xxxxxxxxxxx';