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

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\Core\System\SystemConfig\SystemConfigService;
  6. use Shopware\Storefront\Page\Navigation\NavigationPage;
  7. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedEvent;
  8. use Shopware\Storefront\Page\Page;
  9. use Shopware\Storefront\Page\PageLoadedEvent;
  10. use Shopware\Storefront\Page\Product\ProductPage;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class PluginConfigSubscriber implements EventSubscriberInterface
  13. {
  14.     public const DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA 'DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA';
  15.     /**
  16.      * @var PluginConfigFetcher
  17.      */
  18.     private $pluginConfigFetcher;
  19.     /**
  20.      * @param PluginConfigFetcher $pluginConfigFetcher
  21.      */
  22.     public function __construct(PluginConfigFetcher $pluginConfigFetcher)
  23.     {
  24.         $this->pluginConfigFetcher $pluginConfigFetcher;
  25.     }
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             NavigationPageLoadedEvent::class => 'addInstallment'
  30.         ];
  31.     }
  32.     /**
  33.      * @param PageLoadedEvent $event
  34.      * @throws InconsistentCriteriaIdsException
  35.      */
  36.     public function addInstallment(PageLoadedEvent $event)
  37.     {
  38.         /** @var Page|ProductPage|NavigationPage $page */
  39.         $page $event->getPage();
  40.         $pluginConfig $this->pluginConfigFetcher->getPluginConfigArray();
  41.         $pluginConfigStruct = new PluginConfigStruct(
  42.             $pluginConfig['googleApiKey'] ?? ''
  43.         );
  44.         $page->addExtension(
  45.             self::DREISC_CMS_PRO_INSTALLMENT_PLUGIN_CONFIG_DATA,
  46.             $pluginConfigStruct
  47.         );
  48.     }
  49. }