<?php
/*
* @since 1.0.0
* @copyright Copyright (C) 2020 ArtMedia. All rights reserved.
* @website http://artmedia.biz.pl
* @author Arkadiusz Tobiasz
* @email kontakt@artmedia.biz.pl
*/
namespace App\EventSubscriber\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Twig\Environment;
use App\Events\Core\HomepageWidgetAddEvent;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class WidgetSubscriber implements EventSubscriberInterface
{
private $twig;
public function __construct(
Environment $twig,
AuthenticationUtils $authenticationHelper
) {
$this->authenticationHelper = $authenticationHelper;
$this->twig = $twig;
}
public static function getSubscribedEvents(): array
{
return [
HomepageWidgetAddEvent::NAME => 'onHomepageWidgetAddEvent',
];
}
public function onHomepageWidgetAddEvent(HomepageWidgetAddEvent $event): void
{
$user = $event->getUser();
if (!$user) {
$event->addWidget(
'login',
$this->twig->render('user/widget/login.html.twig', [
'last_username' => $this->authenticationHelper->getLastUsername(),
'error' => $this->authenticationHelper->getLastAuthenticationError(),
]),
'left',
2
);
}
}
}