From b9b76327cb2de3b8c104975f31f34c022c8d73b4 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Mon, 6 Nov 2017 14:00:51 -0500
Subject: [PATCH] Update VuFindTheme module for ServiceManager v3.

---
 module/VuFindTheme/Module.php                   |  9 ++++++---
 .../src/VuFindTheme/InjectTemplateListener.php  | 17 +++++++++--------
 .../ThemeInjectTemplateListenerTest.php         |  2 +-
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/module/VuFindTheme/Module.php b/module/VuFindTheme/Module.php
index 6c900e455a9..15c58f47cc2 100644
--- a/module/VuFindTheme/Module.php
+++ b/module/VuFindTheme/Module.php
@@ -89,12 +89,15 @@ class Module
     {
         return [
             'factories' => [
-                'headLink' => 'VuFindTheme\View\Helper\Factory::getHeadLink',
-                'headScript' => 'VuFindTheme\View\Helper\Factory::getHeadScript',
                 'headThemeResources' =>
                     'VuFindTheme\View\Helper\Factory::getHeadThemeResources',
                 'imageLink' => 'VuFindTheme\View\Helper\Factory::getImageLink',
-                'inlineScript' =>
+                // We have to override the Zend helpers using canonical names:
+                'Zend\View\Helper\HeadLink' =>
+                    'VuFindTheme\View\Helper\Factory::getHeadLink',
+                'Zend\View\Helper\HeadScript' =>
+                    'VuFindTheme\View\Helper\Factory::getHeadScript',
+                'Zend\View\Helper\InlineScript' =>
                     'VuFindTheme\View\Helper\Factory::getInlineScript',
             ],
         ];
diff --git a/module/VuFindTheme/src/VuFindTheme/InjectTemplateListener.php b/module/VuFindTheme/src/VuFindTheme/InjectTemplateListener.php
index b074c98ec32..fdbb9d8b923 100644
--- a/module/VuFindTheme/src/VuFindTheme/InjectTemplateListener.php
+++ b/module/VuFindTheme/src/VuFindTheme/InjectTemplateListener.php
@@ -54,17 +54,18 @@ class InjectTemplateListener extends \Zend\Mvc\View\Http\InjectTemplateListener
     }
 
     /**
-     * Determine the top-level namespace of the controller
+     * Strip namespace part off controller name for compatibility with theme
+     * system.
      *
-     * @param string $controller Controller name
+     * @param string $controller controller FQCN
      *
-     * @return string
-     *
-     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+     * @return string|false template name or false if controller was not matched
      */
-    protected function deriveModuleNamespace($controller)
+    public function mapController($controller)
     {
-        // Namespaces just make the theme system more confusing; ignore them:
-        return '';
+        $initial = parent::mapController($controller);
+        $parts = explode('/', $initial);
+        array_shift($parts);
+        return implode('/', $parts);
     }
 }
diff --git a/module/VuFindTheme/tests/unit-tests/src/VuFindTest/ThemeInjectTemplateListenerTest.php b/module/VuFindTheme/tests/unit-tests/src/VuFindTest/ThemeInjectTemplateListenerTest.php
index ccb9f4aaf0e..8cbd2fc0bce 100644
--- a/module/VuFindTheme/tests/unit-tests/src/VuFindTest/ThemeInjectTemplateListenerTest.php
+++ b/module/VuFindTheme/tests/unit-tests/src/VuFindTest/ThemeInjectTemplateListenerTest.php
@@ -49,7 +49,7 @@ class ThemeInjectTemplateListenerTest extends Unit\TestCase
     {
         $l = new InjectTemplateListener();
         $this->assertEquals(
-            '', $this->callMethod($l, 'deriveModuleNamespace', ['dummy'])
+            'search', $l->mapController('VuFind\Controller\SearchController')
         );
     }
 
-- 
GitLab