custom/plugins/DreiscCmsPro/src/Subscriber/Installment/PluginConfig/PluginConfigSubscriber.php line 33

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.     public const DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA = 'DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA';
  14.     public function __construct(PluginConfigFetcher $pluginConfigFetcher)
  15.     {
  16.         $this->pluginConfigFetcher = $pluginConfigFetcher;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             NavigationPageLoadedEvent::class => 'addInstallment'
  22.         ];
  23.     }
  24.     /**
  25.      * @throws InconsistentCriteriaIdsException
  26.      */
  27.     public function addInstallment(PageLoadedEvent $event)
  28.     {
  29.         /** @var Page|ProductPage|NavigationPage $page */
  30.         $page = $event->getPage();
  31.         $pluginConfig = $this->pluginConfigFetcher->getPluginConfigArray();
  32.         $pluginConfigStruct = new PluginConfigStruct(
  33.             $pluginConfig['googleApiKey'] ?? ''
  34.         );
  35.         $page->addExtension(
  36.             self::DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA,
  37.             $pluginConfigStruct
  38.         );
  39.     }
  40. }