<?php
declare(strict_types=1);
/*
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Swag\AmazonPay\Storefront\EventListeners;
use Shopware\Storefront\Page\Account\Login\AccountLoginPageLoadedEvent;
use Shopware\Storefront\Page\Account\Profile\AccountProfilePageLoadedEvent;
use Shopware\Storefront\Page\PageLoadedEvent;
use Swag\AmazonPay\Components\Button\ButtonProviderInterface;
use Swag\AmazonPay\Storefront\Page\Extension\AmazonLoginButtonExtension;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AmazonLoginButtonEventListener implements EventSubscriberInterface
{
/**
* @var ButtonProviderInterface
*/
private $buttonProvider;
public function __construct(
ButtonProviderInterface $buttonProvider
) {
$this->buttonProvider = $buttonProvider;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array
{
return [
AccountLoginPageLoadedEvent::class => 'addAmazonLoginButtonExtension',
AccountProfilePageLoadedEvent::class => 'addAmazonLoginButtonExtension',
];
}
/**
* @param AccountLoginPageLoadedEvent|AccountProfilePageLoadedEvent $event
*/
public function addAmazonLoginButtonExtension(PageLoadedEvent $event): void
{
$buttonExtension = $this->buttonProvider->getAmazonLoginButton($event);
if ($buttonExtension === null) {
return;
}
$event->getPage()->addExtension(AmazonLoginButtonExtension::EXTENSION_NAME, $buttonExtension);
}
}