We introduced a bug in #1895266: Convert views to use the ModuleHandler

// Let the themes play too, because pre render is a very themey thing.
       foreach ($GLOBALS['base_theme_info'] as $base) {
-        $function = $base->name . '_views_pre_render';
-        if (function_exists($function)) {
-          $function($this);
-        }
-      }
-      $function = $GLOBALS['theme'] . '_views_pre_render';
-      if (function_exists($function)) {
-        $function($this);
+        $module_handler->invoke($base, 'views_pre_render', array($this));
       }
     // Let the themes play too, because post render is a very themey thing.
     foreach ($GLOBALS['base_theme_info'] as $base) {
-      $function = $base->name . '_views_post_render';
-      if (function_exists($function)) {
-        $function($this);
-      }
-    }
-    $function = $GLOBALS['theme'] . '_views_post_render';
-    if (function_exists($function)) {
-      $function($this, $this->display_handler->output, $cache);
+      $module_handler->invoke($base, 'views_post_render', array($this));
     }

Both hunks assume the ModuleHandler::invoke can accept an object as the first argument but it can't... the original code that did $base->name was correct.

  /**
   * Invokes a hook in a particular module.
   *
   * @param string $module
   *   The name of the module (without the .module extension).
   * @param string $hook
   *   The name of the hook to invoke.
   * @param ...
   *   Arguments to pass to the hook implementation.
   *
   * @return mixed
   *   The return value of the hook implementation.
   */
  public function invoke($module, $hook, $args = array());
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott’s picture

Status: Active » Needs review
FileSize
1.15 KB

here's a patch

xjm’s picture

Issue tags: +Needs tests

Sweet, thanks @alexpott!

Status: Needs review » Needs work

The last submitted patch, 1972768.views-with-base-theme.1.patch, failed testing.

dawehner’s picture

Issue tags: +VDC

Missing tag

patrickd’s picture

Status: Needs work » Needs review
patrickd’s picture

Status: Needs review » Reviewed & tested by the community

simple bug, simple patch, lets get this in

patrickd’s picture

Status: Reviewed & tested by the community » Needs work

awww.. needs tests

wondering what to test here though?

damiankloip’s picture

Assigned: Unassigned » damiankloip

I think I know what we can do here...

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.86 KB

So, Maybe we could do something like this? Not sure if it's working.

patrickd’s picture

Some small errors, but basically it was the right direction
- The actual fix of the issue was missing (patch #1)
- The hooks were already implemented in the views_test_data module (but in views_test_data.views_execution.inc)

damiankloip’s picture

Yeha, sorry. That was a really rough patch to outline the method.

Nice, they look like good improvements to me, might as well re use the pre and post render hook implementations from views_test_data.

patrickd’s picture

No probs, it was a good outline.

1972768-10.patch is already re-using these implementations!

dawehner’s picture

+++ b/core/modules/views/lib/Drupal/views/Tests/ViewsHooksTest.phpundefined
@@ -94,6 +94,20 @@ public function testHooks() {
+    $this->container->get('state')->set('views_hook_test_views_pre_render', FALSE);
+    $this->container->get('state')->set('views_hook_test_views_post_render', FALSE);
...
+    $this->assertTrue($this->container->get('state')->get('views_hook_test_views_pre_render'), 'The hook_views_pre_render was invoked in the base theme.');
+    $this->assertTrue($this->container->get('state')->get('views_hook_test_views_post_render'), 'The hook_views_post_render was invoked in the base theme.');

Just in case you want to rerole ... we could store $this->container->get('state') in a variable so that would be easier to read.

patrickd’s picture

Status: Needs review » Needs work

oops, well when a patch is supposed to fail, for sure it passes XD

Turns out that using the existing hook implementations from views_test_data aren't a very good idea, because they always get called on views->render(), so to test whether they were called as "base theme", we have to count how often they've been called.
That kind of sucks and states are never good for testing..

someone spontaneously has a better approach to test this?

damiankloip’s picture

Assigned: damiankloip » Unassigned

Yeah, it's a tricky thing, because we are dealing with good ol' fashioned hooks we can't mock anything :/

Unfortunately, I think we might need to go with a mixture of your last patch, and my initial patch (using different hooks that are called for the base theme).

Berdir’s picture