custom/plugins/SwagAmazonPay/src/Storefront/EventListeners/AmazonLoginButtonEventListener.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * (c) shopware AG <info@shopware.com>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Swag\AmazonPay\Storefront\EventListeners;
  9. use Shopware\Storefront\Page\Account\Login\AccountLoginPageLoadedEvent;
  10. use Shopware\Storefront\Page\Account\Profile\AccountProfilePageLoadedEvent;
  11. use Shopware\Storefront\Page\PageLoadedEvent;
  12. use Swag\AmazonPay\Components\Button\ButtonProviderInterface;
  13. use Swag\AmazonPay\Storefront\Page\Extension\AmazonLoginButtonExtension;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class AmazonLoginButtonEventListener implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var ButtonProviderInterface
  19.      */
  20.     private $buttonProvider;
  21.     public function __construct(
  22.         ButtonProviderInterface $buttonProvider
  23.     ) {
  24.         $this->buttonProvider $buttonProvider;
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             AccountLoginPageLoadedEvent::class => 'addAmazonLoginButtonExtension',
  33.             AccountProfilePageLoadedEvent::class => 'addAmazonLoginButtonExtension',
  34.         ];
  35.     }
  36.     /**
  37.      * @param AccountLoginPageLoadedEvent|AccountProfilePageLoadedEvent $event
  38.      */
  39.     public function addAmazonLoginButtonExtension(PageLoadedEvent $event): void
  40.     {
  41.         $buttonExtension $this->buttonProvider->getAmazonLoginButton($event);
  42.         if ($buttonExtension === null) {
  43.             return;
  44.         }
  45.         $event->getPage()->addExtension(AmazonLoginButtonExtension::EXTENSION_NAME$buttonExtension);
  46.     }
  47. }