I had implemented hook_views_post_render() in a custom module and I discovered that I received an error when I forced the class in the function declaration.

With freshly cleared caches, and the exception throwing in Renderer.php (ln 485) being commented out, the hook is being passed Drupal\views\Plugin\views\cache\None instead of Drupal\Core\Cache\CacheBackendInterface

function rest_custom_views_post_render(ViewExecutable $view, &$output, CacheBackendInterface $cache) {
}

With Renderer.php in its default state, I get a the following error as an anonymous user:

LogicException: A stray drupal_render() invocation with $is_root_call = TRUE is causing bubbling of attached assets to break. in Drupal\Core\Render\Renderer->doRender() (line 485 of core/lib/Drupal/Core/Render/Renderer.php).

If I remove the class name from the $cache variable, everything works as expected.

function rest_custom_views_post_render(ViewExecutable $view, &$output, $cache) {
}

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug, as its broken documentatio.
Issue priority Normal, as its not an often used API
Unfrozen changes Unfrozen because it only changes documentation.
Disruption No discruption

Comments

dawehner’s picture

I'm curious, what is inside your hook?

blake.thompson’s picture

I commented out everything inside the hook and it still threw the error.

borisson_’s picture

Status: Active » Needs review
Issue tags: -views, -anonymous users +VDC, +document hooks
StatusFileSize
new1.24 KB

It's actually an instance of CachePluginBase that should be expected here, not an instance of CacheBackendInterface. I changed the documentation to be correct.

dawehner’s picture

Component: views.module » documentation
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

+1 Added a beta eval

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Too many caches. Committed 3f8677b and pushed to 8.0.x. Thanks!

borisson_’s picture

@alexpott: I can't see this commit in http://cgit.drupalcode.org/drupal/log/, did you do git push?

olli’s picture

Status: Fixed » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

  • alexpott committed 3f8677b on 8.0.x
    Issue #2544922 by borisson_: hook_views_post_render causes "A stray...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.