Hallo!
Ich teste gerade die neue Pluginentwicklung.
In einem Subscriber versuche ich mir bestimmte Daten an die View zu geben:
class FrontendSubscriber implements EventSubscriberInterface
{
const CONFIG_NAMESPACE = 'CompraSW6Test.config.';
/**
* @var SystemConfigService
*/
private $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
public static function getSubscribedEvents()
{
return [
HeaderPageletLoadedEvent::NAME => 'onHeaderPageletLoaded'
];
}
/**
* @param HeaderPageletLoadedEvent $event
* @throws \Shopware\Core\System\SystemConfig\Exception\InvalidDomainException
*/
public function onHeaderPageletLoaded(HeaderPageletLoadedEvent $event)
{
if (!$this->systemConfigService->get('CompraSW6Test.config.active')) {
return;
}
$pluginConfig = $this->systemConfigService->getDomain(self::CONFIG_NAMESPACE);
$event->getPagelet()->assign($pluginConfig);
}
}
Die Daten kommen auch in der View an. Wenn ich mir die Variablen mit {{ dump() }} ausgeben lasse, wird mir folgendes angezeigt:
array:9 [▼
"page" => NavigationPage {#3106 ▼
#cmsPage: CmsPageEntity {#3114 ▶}
#header: HeaderPagelet {#2050 ▼
-navigation: Tree {#2825 ▶}
-offcanvasNavigation: Tree {#2975 ▶}
-languages: LanguageCollection {#3006 ▶}
-currencies: CurrencyCollection {#3048 ▶}
-activeLanguage: LanguageEntity {#3007 ▶}
-activeCurrency: CurrencyEntity {#1047 ▶}
-serviceMenu: CategoryCollection {#2124 ▶}
#extensions: []
+"CompraSW6Test.config.active": true
+"CompraSW6Test.config.customText": "custom text"
+"CompraSW6Test.config.readonlyText": "readonly"
+"CompraSW6Test.config.selectColor": "red"
+"CompraSW6Test.config.selectStyle": array:1 [▶]
}
#footer: FooterPagelet {#3062 ▶}
#context: SalesChannelContext {#1632 ▶}
#extensions: []
}
"shopware" => array:3 [▶]
"controllerName" => "Navigation"
"controllerAction" => "home"
"context" => SalesChannelContext {#1632 ▶}
"activeRoute" => "frontend.home.page"
"formViolations" => null
"app" => AppVariable {#268 ▶}
"isHMRMode" => false
Ich versuche nun verzweifelt mir die Variable für den CustomText im Header ausgeben zu lassen, allerdings wird nichts ausgegeben:
{% sw_extends '@Storefront/layout/header/top-bar.html.twig' %}
{% block layout_header_top_bar_language %}
{{ page.header.CompraSW6Test.config.customText }}
{% if context.customer %}
{{ 'compra-sw6test.index.salutationText'|trans }} {{ context.customer.firstName }} {{ context.customer.lastName }}
(Abmelden)
{% endif %}
{{ parent() }}
{% endblock %}