Completed
Push — master ( ba8ed9...770316 )
by Jeroen
06:11
created

EventSubscriber/AdminListSubscriber.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminListBundle\EventSubscriber;
4
5
use Kunstmaan\AdminListBundle\Entity\OverviewNavigationInterface;
6
use Kunstmaan\NodeBundle\Event\Events;
7
use Kunstmaan\NodeBundle\Event\NodeEvent;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\Routing\RouterInterface;
11
12
/**
13
 * Class AdminListSubscriber.
14
 */
15
class AdminListSubscriber implements EventSubscriberInterface
16
{
17
    /**
18
     * @var RouterInterface
19
     */
20
    private $router;
21
22
    /**
23
     * ArticleSubscriber constructor.
24
     *
25
     * @param RouterInterface $router
26
     */
27
    public function __construct(RouterInterface $router)
28
    {
29
        $this->router = $router;
30
    }
31
32
    /**
33
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<*,string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
34
     */
35
    public static function getSubscribedEvents()
36
    {
37
        return [
38
            Events::POST_DELETE => 'postDelete',
39
        ];
40
    }
41
42
    /**
43
     * @param NodeEvent $event
44
     */
45
    public function postDelete(NodeEvent $event)
46
    {
47
        $page = $event->getPage();
48
49
        // Redirect to admin list when deleting a page that implements the OverviewNavigationInterface.
50
        if ($page instanceof OverviewNavigationInterface) {
51
            $route = $this->router->generate($page->getOverViewRoute());
52
            $response = new RedirectResponse($route);
53
54
            $event->setResponse($response);
55
        }
56
    }
57
}
58