hook_views_post_execute() don't work on AJAX View with exposed filters after 1st refresh I have a View which returns 5 entities of the same type. AJAX - enabled, filters and exposed filters, all working fine.

I need to add a new result, a user - defined entity, at the top of the View results. This programmatically added row should not be affected when the exposed filters are used and should remain at the top of the View, on top of the other 5 returned results, no matter what.

I managed to add this with hook_views_post_execute() but when I use the exposed filters the View returns to its original results and my addition is lost, because AJAX is enabled on this View. hook_views_post_execute() doesn't seem to have any effect after the initial page load.

What is a good alternative for this scenario ie alter the View in a way that's not affected by the AJAX refresh?
When checking the current route match in a Views Ajax request you get the route of the Views Ajax endpoint views/ajax and not the route of the page where the View is placed on.

However, Ajax requests contain the original path of the View and ViewAjaxController::ajaxView() puts this path in the global current path stack (for the pager to work correctly).

So if the path is no longer in the request

$path = \Drupal::request()-&gt;request-&gt;get('view_path');


it should be transfered to:

$path = \Drupal::service('path.current')-&gt;getPath();


Which should then point to the node route you are looking for.