How do I implement hook_views_post_execute I am attempting to modify the output of view programmatically using hook_views_post_execute. 

I created the usual module structure (in this case using drupal generate:module.

I am able to use other hooks (such as hook_entity_view)successfully. 

However, hook_views_post_execute causes blows up the website with the message 


  The website encountered an unexpected error. Please try again later.


The code block is right out of api.drupal.org.

/**
 * @param ViewExecutable $view
 */
function idm_views_post_execute(ViewExecutable $view) {

  // If there are more than 100 results, show a message that encourages the user
  // to change the filter settings.
  // (This action could be performed later in the execution process, but not
  // earlier.)
  $temp = $view;

  if ($view-&gt;total_rows &gt; 100) {
    \Drupal::messenger()
      -&gt;addStatus(t('You have more than 100 hits. Use the filter settings to narrow down your list.'));
  }
}
My guess is you did not include the use statement at the top of your file that tells the application how to locate the class ViewExecutable. This is a PHP construct and not Drupal specific, which is why it is not always mentioned explicitly in the documentation.

At the top of your file, add:

use Drupal\views\ViewExecutable;

The incoming argument to the hook is of type ViewExecutable, but PHP does not know how to find that class, so it errors out unless you either use the use statement, or change the function signature to:

function idm_views_post_execute(Drupal\views\ViewExecutable $view)


Clear cache and reload. If the error persists, you'll need to provide log(s) to indicate what the actual error that occurred was.

If you copied and pasted the code here for hook_entity_view that would explain why that worked for you:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_entity_view/8.6.x

The example here has the full path in the argument list.

hook_entity_view(array &amp;$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode)