From ba035c0a408691c061989aeca98ba37867c16b08 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Thu, 28 Jan 2021 06:39:09 -0500
Subject: [PATCH] TemplateBased ContentBlock: Fix problem with i18n of PHTML
 templates. (#1836)

---
 .../src/VuFind/ContentBlock/TemplateBased.php  |  2 +-
 .../ContentBlock/TemplateBasedTest.php         | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/module/VuFind/src/VuFind/ContentBlock/TemplateBased.php b/module/VuFind/src/VuFind/ContentBlock/TemplateBased.php
index 52968f10962..2c8723c8ce1 100644
--- a/module/VuFind/src/VuFind/ContentBlock/TemplateBased.php
+++ b/module/VuFind/src/VuFind/ContentBlock/TemplateBased.php
@@ -122,7 +122,7 @@ class TemplateBased implements ContentBlockInterface
     protected function getContextForPhtml(string $page, string $path): array
     {
         return [
-            'templateName' => $this->templateName,
+            'templateName' => $page,
         ];
     }
 }
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ContentBlock/TemplateBasedTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ContentBlock/TemplateBasedTest.php
index 6fde869b38f..dbc9ede0862 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/ContentBlock/TemplateBasedTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ContentBlock/TemplateBasedTest.php
@@ -58,6 +58,24 @@ class TemplateBasedTest extends \PHPUnit\Framework\TestCase
         $this->assertEquals(['templateName' => 'foo'], $block->getContext());
     }
 
+    /**
+     * Test functionality of .phtml content block w/ i18n.
+     *
+     * @return void
+     */
+    public function testI18nPhtmlFunctionality()
+    {
+        $locator = $this->getMockBuilder(\VuFind\Content\PageLocator::class)
+            ->disableOriginalConstructor()
+            ->getMock();
+        $locator->expects($this->once())->method('determineTemplateAndRenderer')
+            ->with($this->equalTo('templates/ContentBlock/TemplateBased/'), $this->equalTo('foo'))
+            ->will($this->returnValue(['renderer' => 'phtml', 'page' => 'foo_en', 'path' => '/path/to/foo_en.phtml']));
+        $block = new \VuFind\ContentBlock\TemplateBased($locator);
+        $block->setConfig('foo');
+        $this->assertEquals(['templateName' => 'foo_en'], $block->getContext());
+    }
+
     /**
      * Test basic functionality of Markdown content block.
      *
-- 
GitLab