function hook_views_post_render
Same name in other branches
- 9 core/modules/views/views.api.php \hook_views_post_render()
- 8.9.x core/modules/views/views.api.php \hook_views_post_render()
- 11.x core/modules/views/views.api.php \hook_views_post_render()
Post-process any render data.
The module or theme may add, modify or remove elements in $output after rendering.
If a module wishes to act on the rendered HTML of the view rather than the structured content array, it may use this hook to add a #post_render callback:
// The object must implement \Drupal\Core\Security\TrustedCallbackInterface.
$output['#post_render'][] = '\\Drupal\\my_module\\View::postRender';
See \Drupal\Core\Render\RendererInterface::render() for #post_render documentation.
Alternatively, it could also implement hook_preprocess_HOOK() for the particular view template, if there is one.
Parameters
\Drupal\views\ViewExecutable $view: The view object being processed.
array $output: A structured content array representing the view output. The given array depends on the style plugin and can be either a render array or an array of render arrays.
\Drupal\views\Plugin\views\cache\CachePluginBase $cache: The cache settings.
See also
Related topics
5 functions implement hook_views_post_render()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- media_library_views_post_render in core/
modules/ media_library/ media_library.module - Implements hook_views_post_render().
- test_basetheme_views_post_render in core/
modules/ system/ tests/ themes/ test_basetheme/ test_basetheme.theme - Implements hook_views_post_render().
- test_subtheme_views_post_render in core/
modules/ system/ tests/ themes/ test_subtheme/ test_subtheme.theme - Implements hook_views_post_render().
- views_test_config_views_post_render in core/
modules/ views/ tests/ modules/ views_test_config/ views_test_config.module - Implements hook_views_post_render().
- views_test_data_views_post_render in core/
modules/ views/ tests/ modules/ views_test_data/ views_test_data.views_execution.inc - Implements hook_views_post_render().
1 invocation of hook_views_post_render()
- ViewExecutable::render in core/
modules/ views/ src/ ViewExecutable.php - Renders this view for a certain display.
File
-
core/
modules/ views/ views.api.php, line 874
Code
function hook_views_post_render(ViewExecutable $view, array &$output, CachePluginBase $cache) {
// When using full pager, disable any time-based caching if there are fewer
// than 10 results.
if ($view->pager instanceof Drupal\views\Plugin\views\pager\Full && $cache instanceof Drupal\views\Plugin\views\cache\Time && count($view->result) < 10) {
$cache->options['results_lifespan'] = 0;
$cache->options['output_lifespan'] = 0;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.