Commit bcbe3c63 authored by alexpott's avatar alexpott
Browse files

Issue #2412167 by geertvd, dawehner, Sutharsan: hook_views_post_render fails in a theme

parent 57afdabd
......@@ -4,6 +4,7 @@
* @file
* Add hooks for tests to use.
*/
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\ViewExecutable;
/**
......@@ -17,7 +18,7 @@ function test_basetheme_views_pre_render(ViewExecutable $view) {
/**
* Implements hook_views_post_render().
*/
function test_basetheme_views_post_render(ViewExecutable $view) {
function test_basetheme_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
// We append the function name to the title for test to check for.
$view->setTitle($view->getTitle() . ":" . __FUNCTION__);
}
......
......@@ -5,6 +5,7 @@
* Add hooks for tests to use.
*/
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\ViewExecutable;
/**
......@@ -18,9 +19,12 @@ function test_subtheme_views_pre_render(ViewExecutable $view) {
/**
* Implements hook_views_post_render().
*/
function test_subtheme_views_post_render(ViewExecutable $view) {
function test_subtheme_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
// We append the function name to the title for test to check for.
$view->setTitle($view->getTitle() . ":" . __FUNCTION__);
if ($view->id() == 'test_page_display') {
$output['#rows'][0]['#title'] = t('%total_rows items found.', array('%total_rows' => $view->total_rows));
}
}
/**
......
......@@ -65,11 +65,17 @@ protected function setUp() {
*/
public function testHooks() {
$view = Views::getView('test_view');
$view->setDisplay();
// Test each hook is found in the implementations array and is invoked.
foreach (static::$hooks as $hook => $type) {
$this->assertTrue($this->moduleHandler->implementsHook('views_test_data', $hook), format_string('The hook @hook was registered.', array('@hook' => $hook)));
if ($hook == 'views_post_render') {
$this->moduleHandler->invoke('views_test_data', $hook, array($view, &$view->display_handler->output, $view->display_handler->getPlugin('cache')));
continue;
}
switch ($type) {
case 'view':
$this->moduleHandler->invoke('views_test_data', $hook, array($view));
......
......@@ -74,11 +74,13 @@ public function testThemedViewPage() {
// Make sure a views rendered page is touched.
$this->drupalGet('test_page_display_200');
$this->assertRaw("test_subtheme_views_pre_render", "Views title changed by test_usetheme.test_subtheme_views_pre_render");
$this->assertRaw("test_subtheme_views_post_render", "Views title changed by test_usetheme.test_subtheme_views_post_render");
$this->assertRaw("test_subtheme_views_pre_render", "Views title changed by test_subtheme.test_subtheme_views_pre_render");
$this->assertRaw("test_subtheme_views_post_render", "Views title changed by test_subtheme.test_subtheme_views_post_render");
$this->assertRaw("test_basetheme_views_pre_render", "Views title changed by test_basetheme.test_basetheme_views_pre_render");
$this->assertRaw("test_basetheme_views_post_render", "Views title changed by test_basetheme.test_basetheme_views_post_render");
$this->assertRaw('<em class="placeholder">' . count($this->dataSet()) . '</em> items found.', 'Views group title added by test_subtheme.test_subtheme_views_post_render');
}
}
......@@ -1371,11 +1371,11 @@ public function render($display_id = NULL) {
$themes[] = $active_theme->getName();
// Check for already-cached output.
/** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
if (!empty($this->live_preview)) {
$cache = FALSE;
$cache = Views::pluginManager('cache')->createInstance('none');
}
else {
/** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
$cache = $this->display_handler->getPlugin('cache');
}
......@@ -1431,9 +1431,7 @@ public function render($display_id = NULL) {
$exposed_form->postRender($this->display_handler->output);
if ($cache) {
$cache->postRender($this->display_handler->output);
}
// Let modules modify the view output after it is rendered.
$module_handler->invokeAll('views_post_render', array($this, &$this->display_handler->output, $cache));
......@@ -1442,7 +1440,7 @@ public function render($display_id = NULL) {
foreach ($themes as $theme_name) {
$function = $theme_name . '_views_post_render';
if (function_exists($function)) {
$function($this);
$function($this, $this->display_handler->output, $cache);
}
}
......
......@@ -6,6 +6,7 @@
*/
use Drupal\field\FieldStorageConfigInterface;
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\ViewExecutable;
/**
......@@ -66,7 +67,7 @@ function views_test_data_placeholders() {
/**
* Implements hook_views_post_render().
*/
function views_test_data_views_post_render(ViewExecutable $view) {
function views_test_data_views_post_render(ViewExecutable $view, &$output, CachePluginBase $cache) {
\Drupal::state()->set('views_hook_test_views_post_render', TRUE);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment