Skip to content

Commit b59c619

Browse files
authored
Refactor Config and JsConfigs View Helper to use autowiring (#5081)
1 parent 4152e2b commit b59c619

File tree

5 files changed

+30
-84
lines changed

5 files changed

+30
-84
lines changed

module/VuFind/src/VuFind/View/Helper/Root/Config.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
namespace VuFind\View\Helper\Root;
3131

3232
use VuFind\Config\ConfigManagerInterface;
33+
use VuFind\ServiceManager\Factory\Autowire;
3334

3435
/**
3536
* Config view helper
@@ -40,7 +41,7 @@
4041
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
4142
* @link https://vufind.org/wiki/development Wiki
4243
*/
43-
class Config extends \Laminas\View\Helper\AbstractHelper
44+
class Config
4445
{
4546
/**
4647
* Display date format
@@ -61,8 +62,10 @@ class Config extends \Laminas\View\Helper\AbstractHelper
6162
*
6263
* @param ConfigManagerInterface $configManager Configuration manager
6364
*/
64-
public function __construct(protected ConfigManagerInterface $configManager)
65-
{
65+
public function __construct(
66+
#[Autowire]
67+
protected ConfigManagerInterface $configManager
68+
) {
6669
}
6770

6871
/**
@@ -197,4 +200,14 @@ public function displayLoanType(): bool
197200
return (bool)($this->get('config')->Catalog
198201
->display_loan_type_in_holdings ?? false);
199202
}
203+
204+
/**
205+
* Return this helper instance (for method chaining).
206+
*
207+
* @return Config
208+
*/
209+
public function __invoke()
210+
{
211+
return $this;
212+
}
200213
}

module/VuFind/src/VuFind/View/Helper/Root/ConfigFactory.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

module/VuFind/src/VuFind/View/Helper/Root/JsConfigs.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
namespace VuFind\View\Helper\Root;
3131

32-
use Laminas\View\Helper\AbstractHelper;
33-
3432
/**
3533
* JsConfigs helper for passing configs to Javascript
3634
*
@@ -40,7 +38,7 @@
4038
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
4139
* @link https://vufind.org/wiki/development Wiki
4240
*/
43-
class JsConfigs extends AbstractHelper
41+
class JsConfigs
4442
{
4543
/**
4644
* Config
@@ -74,4 +72,14 @@ public function getJSON(): string
7472
}
7573
return json_encode($this->config);
7674
}
75+
76+
/**
77+
* Return this helper instance.
78+
*
79+
* @return JsConfigs
80+
*/
81+
public function __invoke()
82+
{
83+
return $this;
84+
}
7785
}

module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordDataFormatterTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ protected function getFormatter($additionalConfig = [], $additionalSpecs = [])
298298
// Inject the view object into all of the helpers:
299299
$formatter->setView($view);
300300
foreach ($helpers as $helper) {
301-
$helper->setView($view);
301+
if (method_exists($helper, 'setView')) {
302+
$helper->setView($view);
303+
}
302304
}
303305

304306
return $formatter;

themes/root/theme.config.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
'VuFind\View\Helper\Root\Citation' => 'VuFind\View\Helper\Root\CitationFactory',
2222
'VuFind\View\Helper\Root\CleanHtml' => 'VuFind\View\Helper\Root\CleanHtmlFactory',
2323
'VuFind\View\Helper\Root\Component' => 'Laminas\ServiceManager\Factory\InvokableFactory',
24-
'VuFind\View\Helper\Root\Config' => 'VuFind\View\Helper\Root\ConfigFactory',
2524
'VuFind\View\Helper\Root\CookieConsent' => 'VuFind\View\Helper\Root\CookieConsentFactory',
2625
'VuFind\View\Helper\Root\CookieManager' => 'VuFind\View\Helper\Root\CookieManagerFactory',
2726
'VuFind\View\Helper\Root\ContentBlock' => 'Laminas\ServiceManager\Factory\InvokableFactory',
@@ -47,7 +46,6 @@
4746
'VuFind\View\Helper\Root\Icon' => 'VuFind\View\Helper\Root\IconFactory',
4847
'VuFind\View\Helper\Root\IdentifierLinker' => 'VuFind\View\Helper\Root\IdentifierLinkerFactory',
4948
'VuFind\View\Helper\Root\Ils' => 'VuFind\View\Helper\Root\IlsFactory',
50-
'VuFind\View\Helper\Root\JsConfigs' => 'Laminas\ServiceManager\Factory\InvokableFactory',
5149
'VuFind\View\Helper\Root\JsIcons' => 'VuFind\View\Helper\Root\JsIconsFactory',
5250
'VuFind\View\Helper\Root\JsTranslations' => 'VuFind\View\Helper\Root\JsTranslationsFactory',
5351
'VuFind\View\Helper\Root\KeepAlive' => 'VuFind\View\Helper\Root\KeepAliveFactory',

0 commit comments

Comments
 (0)