自 Shopware 6.4.13.0 以来有一个新功能,您可以在捆绑包类中设置
getTemplatePriority()
来影响模板加载顺序。
我们目前有一个有序列表,其中列出了我们希望如何加载插件并设置
installed_at
日期。它包含自己的插件(custom/
文件夹)以及第3方插件。
有没有办法将其移植到新功能(根据https://stackoverflow.com/a/74139837/288568似乎有必要)?
据我了解,只有插件本身可以设置
setTemplatePriority()
?我们如何注入/更改第三方插件的优先级?
也许可以装饰bundle类?
目前的情况是这样的:
'DmfManuTheme',
'CustomImporter',
'OwnMoreCustomFields',
'CustomListingHeader',
'CustomPrintLayout',
'DevertPdfExport',
'TonurSeoFilterLandingpages6', // must be before CustomTheme/CustomProductListing as it extends listing.html.twig
'CustomApplicationManagement',
'CustomProductListing',
'FroshProductCompare',
'CustomRegistrationProcess',
'mmeesRangeSliderPro',
'CustomProductFilter', // must be after mmeesRangeSliderPro
'CustomContactBanner',
'OwnRadioPropertyFilter',
'OwnHierarchicalAttributes',
'CustomLocalMerchant',
'MoorlFoundation',
'MoorlMerchantFinder',
'MoorlMerchantPicker',
'CustomTheme', // must be after the MoorlMerchant plugins
'CustomProductDownloads',
'CustomFreeSampleOrder',
'NetzpBlog6',
'CrswCleverReachOfficial',
'MoorlFormBuilder',
'NetzpSearchAdvanced6',
'CustomProductNotification',
'CogiEtracker',
'ApplifactionGoogleMapsPlugin',
是的,这是相当多的插件。我们尝试为每个定制制作一个小插件,而不是大型的整体定制插件。
Own
+ Custom
是我们的命名空间,我们可以在其中设置模板优先级。但我相信整个问题不能这样解决。
编辑:
是否可以装饰
\Shopware\Core\Framework\Bundle
- 我对此表示怀疑。
或者编译器会通过帮助吗?
BundleHierarchyBuilder
服务你可以装饰。实现方法buildNamespaceHierarchy
并通过在装饰服务上调用它来获取返回值。这应该为您提供键值对,其中键是捆绑包名称,而值是从捆绑包接收的优先级。然后,您可以设置每个捆绑包的优先级并重新排序。请注意,如果您使用模板扩展应用程序(而不是捆绑包),您可能必须在装饰器中完全重新实现该方法,因为它们的优先级会被初始排序后的版本覆盖。
public function buildNamespaceHierarchy(array $namespaceHierarchy): array
{
$hierarchy = $this->decorated->buildNamespaceHierarchy($namespaceHierarchy);
$extensions = array_diff_key($hierarchy, $namespaceHierarchy);
$extensions['MoorlMerchantFinder'] = 5;
$extensions['TonurSeoFilterLandingpages6'] = 3;
// ...
asort($extensions);
return array_merge(
$extensions,
$namespaceHierarchy
);
}