Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VUFIND-1677] Prepare for laminas-view v3 #4213

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
53bbfc2
Refactor headLink calls to assetPipeline helper.
demiankatz Jan 28, 2025
584c6cc
Move raw CSS into asset pipeline.
demiankatz Jan 28, 2025
fce7069
Refactor headScript/footScript.
demiankatz Jan 28, 2025
41c6f8b
Fix tests.
demiankatz Jan 28, 2025
17aa0c3
Merge branch 'dev' into vufind-1677
demiankatz Jan 30, 2025
1d11278
Align method parameters for consistency/completeness.
demiankatz Jan 30, 2025
f2f212f
Refactor CSS processing to reduce helper calls.
demiankatz Jan 30, 2025
32a7fae
Refactor HeadScript file collection.
demiankatz Jan 30, 2025
23f7fb4
Factor CSS theme handling to AssetPipeline.
demiankatz Jan 30, 2025
eae636f
Fix test.
demiankatz Jan 30, 2025
5c06590
Merge branch 'dev' into vufind-1677
demiankatz Jan 31, 2025
2621205
Factor away HeadLink helper.
demiankatz Jan 31, 2025
a8f5058
Fix test.
demiankatz Jan 31, 2025
a50954b
Add missing return.
demiankatz Jan 31, 2025
4a5ab46
Merge branch 'dev' into vufind-1677
demiankatz Feb 3, 2025
d34081d
Rename helper from assetPipeline to assetManager.
demiankatz Feb 3, 2025
fc75756
Add inlineScript wrappers to AssetManager.
demiankatz Feb 3, 2025
92f14b5
Fix test.
demiankatz Feb 3, 2025
7e3c158
Revert "Fix test."
demiankatz Feb 4, 2025
4c6b337
Update GoogleAnalytics helper to use AssetManager; improve tests.
demiankatz Feb 4, 2025
b315e74
Fix style; port another helper.
demiankatz Feb 4, 2025
f340000
Finish porting helpers to use AssetManager.
demiankatz Feb 4, 2025
47db21d
Refactor nonce handling.
demiankatz Feb 4, 2025
9551cff
Progress on removing internal helpers.
demiankatz Feb 4, 2025
5ee33b4
Only include non-empty nonce.
demiankatz Feb 4, 2025
19acff9
Various fixes.
demiankatz Feb 4, 2025
af33c29
Remove obsolete helper.
demiankatz Feb 4, 2025
9535231
Fix inline script output.
demiankatz Feb 4, 2025
252ba4b
Prevent asset pipeline duplication.
demiankatz Feb 4, 2025
fa002e6
Eliminate FootScript helper.
demiankatz Feb 4, 2025
0543362
Upgrade laminas-view.
demiankatz Feb 4, 2025
13ff958
Remove redundant nonce setting.
demiankatz Feb 5, 2025
42865fe
Merge remote-tracking branch 'origin/dev' into vufind-1677
demiankatz Feb 5, 2025
b3542d1
Factor asset pipeline logic out of asset manager.
demiankatz Feb 5, 2025
80a30d5
Merge remote-tracking branch 'origin/dev' into vufind-1677
demiankatz Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"laminas/laminas-session": "2.21.0",
"laminas/laminas-stdlib": "3.19.0",
"laminas/laminas-validator": "2.64.2",
"laminas/laminas-view": "2.27.0",
"laminas/laminas-view": "2.36.0",
"laminas/laminas-translator": "^1",
"league/commonmark": "2.6.0",
"league/oauth2-client": "^2.7",
Expand Down
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions config/vufind/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ theme = sandal5
; Uncomment the following line to use a different theme for Admin module.
;admin_theme = sandal

; Automatic asset minification and concatenation setting. When active, HeadScript
; and HeadLink will concatenate and minify all viable files to reduce requests and
; load times. This setting is off by default.
; Automatic asset minification and concatenation setting. When active, the asset
; manager helper will concatenate and minify all viable files to reduce requests
; and load times. This setting is off by default.
;
; This configuration takes the form of a semi-colon separated list of
; environment:configuration pairs where "environment" is a possible APPLICATION_ENV
Expand Down
8 changes: 3 additions & 5 deletions module/VuFind/src/VuFind/View/Helper/Root/GoogleAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace VuFind\View\Helper\Root;

use Laminas\View\Helper\HeadScript;

use function is_array;

/**
Expand Down Expand Up @@ -107,11 +105,11 @@ public function __invoke($customUrl = false)
if (!$this->key) {
return '';
}
$inlineScript = $this->getView()->plugin('inlinescript');
$assetManager = $this->getView()->plugin('assetManager');
$url = 'https://www.googletagmanager.com/gtag/js?id=' . urlencode($this->key);
$code = $this->getRawJavascript($customUrl);
return
$inlineScript(HeadScript::FILE, $url, 'SET', ['async' => true]) . "\n"
. $inlineScript(HeadScript::SCRIPT, $code, 'SET');
$assetManager->outputInlineScriptFile($url, attrs: ['async' => true]) . "\n"
. $assetManager->outputInlineScript($code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function getHeadCode()
return '';
}

// phpcs:disable -- line length should be kept for this vendor snippet
$js = <<<END
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
Expand All @@ -77,10 +76,7 @@ public function getHeadCode()
n&&j.setAttribute('nonce',n.nonce||n.getAttribute('nonce'));f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{$this->gtmContainerId}');
END;
// phpcs:enable
$inlineScript = $this->getView()->plugin('inlinescript');
$js = $inlineScript(\Laminas\View\Helper\HeadScript::SCRIPT, $js, 'SET');
return $js;
return $this->getView()->plugin('assetManager')->outputInlineScript($js);
}

/**
Expand All @@ -94,14 +90,12 @@ public function getBodyCode()
return '';
}

// phpcs:disable -- line length should be kept for this vendor snippet
$js = <<<END
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={$this->gtmContainerId}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
END;
// phpcs:enable
return $js;
}
}
4 changes: 1 addition & 3 deletions module/VuFind/src/VuFind/View/Helper/Root/Matomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ public function __invoke(array $params = []): string
} else {
$code = $this->trackPageView();
}

$inlineScript = $this->getView()->plugin('inlinescript');
return $inlineScript(\Laminas\View\Helper\HeadScript::SCRIPT, $code, 'SET');
return $this->getView()->plugin('assetManager')->outputInlineScript($code);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions module/VuFind/src/VuFind/View/Helper/Root/Piwik.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ public function __invoke($params = null)
$code = $this->trackPageView();
}

$inlineScript = $this->getView()->plugin('inlinescript');
return $inlineScript(\Laminas\View\Helper\HeadScript::SCRIPT, $code, 'SET');
return $this->getView()->plugin('assetManager')->outputInlineScript($code);
}

/**
Expand Down
35 changes: 28 additions & 7 deletions module/VuFind/src/VuFindTest/Feature/ViewTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@

namespace VuFindTest\Feature;

use Laminas\View\Renderer\PhpRenderer;
use VuFind\View\Helper\Root\SearchMemory;
use VuFindTest\Container\MockContainer;
use VuFindTheme\View\Helper\AssetManager;
use VuFindTheme\View\Helper\AssetManagerFactory;

/**
* Trait for tests involving Laminas Views.
Expand All @@ -42,13 +46,29 @@
*/
trait ViewTrait
{
/**
* Get a working AssetManager helper.
*
* @param PhpRenderer $renderer View for helper
*
* @return AssetManager
*/
protected function getAssetManager(PhpRenderer $renderer): AssetManager
{
$container = new MockContainer($this);
$factory = new AssetManagerFactory();
$helper = $factory($container, AssetManager::class);
$helper->setView($renderer);
return $helper;
}

/**
* Get a working renderer.
*
* @param array $plugins Custom VuFind plug-ins to register
* @param string $theme Theme directory to load from
*
* @return \Laminas\View\Renderer\PhpRenderer
* @return PhpRenderer
*/
protected function getPhpRenderer($plugins = [], $theme = 'bootstrap5')
{
Expand All @@ -63,13 +83,14 @@ protected function getPhpRenderer($plugins = [], $theme = 'bootstrap5')
$this->getPathForTheme($theme),
]
);
$renderer = new \Laminas\View\Renderer\PhpRenderer();
$renderer = new PhpRenderer();
$renderer->setResolver($resolver);
if (!empty($plugins)) {
$pluginManager = $renderer->getHelperPluginManager();
foreach ($plugins as $key => $value) {
$pluginManager->setService($key, $value);
}
$pluginManager = $renderer->getHelperPluginManager();
if (!isset($plugins['assetManager'])) {
$plugins['assetManager'] = $this->getAssetManager($renderer);
}
foreach ($plugins as $key => $value) {
$pluginManager->setService($key, $value);
}
return $renderer;
}
Expand Down
32 changes: 8 additions & 24 deletions module/VuFindTheme/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function getServiceConfig()
ParentInjectTemplateListener::class => InjectTemplateListener::class,
],
'factories' => [
InjectTemplateListener::class =>
InjectTemplateListenerFactory::class,
AssetPipeline::class => AssetPipelineFactory::class,
InjectTemplateListener::class => InjectTemplateListenerFactory::class,
MixinGenerator::class => ThemeInfoInjectorFactory::class,
Mobile::class => InvokableFactory::class,
ResourceContainer::class => InvokableFactory::class,
Expand All @@ -108,34 +108,18 @@ public function getViewHelperConfig()
{
return [
'factories' => [
View\Helper\FootScript::class =>
View\Helper\PipelineInjectorFactory::class,
View\Helper\AssetManager::class => View\Helper\AssetManagerFactory::class,
View\Helper\ImageLink::class => View\Helper\ImageLinkFactory::class,
View\Helper\HeadLink::class =>
View\Helper\PipelineInjectorFactory::class,
View\Helper\HeadScript::class =>
View\Helper\PipelineInjectorFactory::class,
View\Helper\ParentTemplate::class =>
View\Helper\ParentTemplateFactory::class,
View\Helper\InlineScript::class =>
View\Helper\PipelineInjectorFactory::class,
View\Helper\Slot::class =>
View\Helper\PipelineInjectorFactory::class,
View\Helper\TemplatePath::class =>
View\Helper\TemplatePathFactory::class,
View\Helper\SetupThemeResources::class =>
View\Helper\SetupThemeResourcesFactory::class,
View\Helper\ParentTemplate::class => View\Helper\ParentTemplateFactory::class,
View\Helper\Slot::class => InvokableFactory::class,
View\Helper\TemplatePath::class => View\Helper\TemplatePathFactory::class,
View\Helper\SetupThemeResources::class => View\Helper\SetupThemeResourcesFactory::class,
],
'aliases' => [
'footScript' => View\Helper\FootScript::class,
'assetManager' => View\Helper\AssetManager::class,
// Legacy alias for compatibility with pre-8.0 templates:
'headThemeResources' => View\Helper\SetupThemeResources::class,
'imageLink' => View\Helper\ImageLink::class,
\Laminas\View\Helper\HeadLink::class => View\Helper\HeadLink::class,
\Laminas\View\Helper\HeadScript::class =>
View\Helper\HeadScript::class,
\Laminas\View\Helper\InlineScript::class =>
View\Helper\InlineScript::class,
'parentTemplate' => View\Helper\ParentTemplate::class,
'slot' => View\Helper\Slot::class,
'templatePath' => View\Helper\TemplatePath::class,
Expand Down
Loading