vendor/store.shopware.com/dreisccmspro/src/Subscriber/Installment/PluginConfig/PluginConfigSubscriber.php line 32

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace DreiscCmsPro\Subscriber\Installment\PluginConfig;
  3. use DreiscCmsPro\Core\PluginConfig\PluginConfigFetcher;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  5. use Shopware\Storefront\Page\Navigation\NavigationPage;
  6. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
  7. use Shopware\Storefront\Page\Page;
  8. use Shopware\Storefront\Page\PageLoadedEvent;
  9. use Shopware\Storefront\Page\Product\ProductPage;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class PluginConfigSubscriber implements EventSubscriberInterface
  12. {
  13.     final public const DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA 'DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA';
  14.     public function __construct(private readonly PluginConfigFetcher $pluginConfigFetcher)
  15.     {
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             NavigationPageLoadedEvent::class => 'addInstallment'
  21.         ];
  22.     }
  23.     /**
  24.      * @throws InconsistentCriteriaIdsException
  25.      */
  26.     public function addInstallment(PageLoadedEvent $event)
  27.     {
  28.         /** @var Page|ProductPage|NavigationPage $page */
  29.         $page $event->getPage();
  30.         $pluginConfig $this->pluginConfigFetcher->getPluginConfigArray();
  31.         $pluginConfigStruct = new PluginConfigStruct(
  32.             $pluginConfig['googleApiKey'] ?? ''
  33.         );
  34.         $page->addExtension(
  35.             self::DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA,
  36.             $pluginConfigStruct
  37.         );
  38.     }
  39. }