From e9f8aa8fa925778113199b16eaaabedd72e43a72 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 8 Nov 2017 15:11:08 -0500 Subject: [PATCH] Fix ServiceManager v3 compatibility of ResultFeed plugin. (#1072) - Adjust service names for forward-compatibility - Move initialization to factory to avoid redundant work --- .../src/VuFind/View/Helper/Root/Factory.php | 14 ++++++++++++++ .../VuFind/View/Helper/Root/ResultFeed.php | 19 ++++++++++--------- .../View/Helper/Root/ResultFeedTest.php | 1 + themes/root/theme.config.php | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php index fad1fa48732..efccfd753ea 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Factory.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Factory.php @@ -446,6 +446,20 @@ class Factory ); } + /** + * Construct the ResultFeed helper. + * + * @param ServiceManager $sm Service manager. + * + * @return ResultFeed + */ + public static function getResultFeed(ServiceManager $sm) + { + $helper = new ResultFeed(); + $helper->registerExtensions($sm); + return $helper; + } + /** * Construct the SafeMoneyFormat helper. * diff --git a/module/VuFind/src/VuFind/View/Helper/Root/ResultFeed.php b/module/VuFind/src/VuFind/View/Helper/Root/ResultFeed.php index c4039d3d9f2..a8665fa27f9 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/ResultFeed.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/ResultFeed.php @@ -31,6 +31,7 @@ use DateTime; use VuFind\I18n\Translator\TranslatorAwareInterface; use Zend\Feed\Writer\Feed; use Zend\Feed\Writer\Writer as FeedWriter; +use Zend\ServiceManager\ServiceManager; use Zend\View\Helper\AbstractHelper; /** @@ -66,26 +67,28 @@ class ResultFeed extends AbstractHelper implements TranslatorAwareInterface } /** - * Set up custom extensions. + * Set up custom extensions (should be called by factory). + * + * @param ServiceManager $sm Service manager. * * @return void */ - protected function registerExtensions() + public function registerExtensions(ServiceManager $sm) { - $manager = new \Zend\Feed\Writer\ExtensionPluginManager(); + $manager = new \Zend\Feed\Writer\ExtensionPluginManager($sm); $manager->setInvokableClass( - 'dublincorerendererentry', + 'DublinCore\Renderer\Entry', 'VuFind\Feed\Writer\Extension\DublinCore\Renderer\Entry' ); $manager->setInvokableClass( - 'dublincoreentry', 'VuFind\Feed\Writer\Extension\DublinCore\Entry' + 'DublinCore\Entry', 'VuFind\Feed\Writer\Extension\DublinCore\Entry' ); $manager->setInvokableClass( - 'opensearchrendererfeed', + 'OpenSearch\Renderer\Feed', 'VuFind\Feed\Writer\Extension\OpenSearch\Renderer\Feed' ); $manager->setInvokableClass( - 'opensearchfeed', 'VuFind\Feed\Writer\Extension\OpenSearch\Feed' + 'OpenSearch\Feed', 'VuFind\Feed\Writer\Extension\OpenSearch\Feed' ); FeedWriter::setExtensionManager($manager); FeedWriter::registerExtension('OpenSearch'); @@ -103,8 +106,6 @@ class ResultFeed extends AbstractHelper implements TranslatorAwareInterface */ public function __invoke($results, $currentPath = null) { - $this->registerExtensions(); - // Determine base URL if not already provided: if (is_null($currentPath)) { $currentPath = $this->getView()->plugin('currentpath')->__invoke(); diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/View/Helper/Root/ResultFeedTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/View/Helper/Root/ResultFeedTest.php index e93e8f27157..313ce64da85 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/View/Helper/Root/ResultFeedTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/View/Helper/Root/ResultFeedTest.php @@ -123,6 +123,7 @@ class ResultFeedTest extends \VuFindTest\Unit\ViewHelperTestCase $results->getParams()->initFromRequest($request); $helper = new ResultFeed(); + $helper->registerExtensions($this->getServiceManager()); $helper->setTranslator($this->getMockTranslator()); $helper->setView($this->getPhpRenderer($this->getPlugins())); $feed = $helper->__invoke($results, '/test/path'); diff --git a/themes/root/theme.config.php b/themes/root/theme.config.php index 702072f5edf..01a2578a348 100644 --- a/themes/root/theme.config.php +++ b/themes/root/theme.config.php @@ -31,6 +31,7 @@ return [ 'recordDataFormatter' => 'VuFind\View\Helper\Root\RecordDataFormatterFactory', 'recordLink' => 'VuFind\View\Helper\Root\Factory::getRecordLink', 'related' => 'VuFind\View\Helper\Root\Factory::getRelated', + 'resultfeed' => 'VuFind\View\Helper\Root\Factory::getResultFeed', 'safeMoneyFormat' => 'VuFind\View\Helper\Root\Factory::getSafeMoneyFormat', 'searchbox' => 'VuFind\View\Helper\Root\Factory::getSearchBox', 'searchMemory' => 'VuFind\View\Helper\Root\Factory::getSearchMemory', @@ -53,7 +54,6 @@ return [ 'printms' => 'VuFind\View\Helper\Root\Printms', 'recommend' => 'VuFind\View\Helper\Root\Recommend', 'renderArray' => 'VuFind\View\Helper\Root\RenderArray', - 'resultfeed' => 'VuFind\View\Helper\Root\ResultFeed', 'sortFacetList' => 'VuFind\View\Helper\Root\SortFacetList', 'summon' => 'VuFind\View\Helper\Root\Summon', 'transEsc' => 'VuFind\View\Helper\Root\TransEsc', -- GitLab