vendor/kunstmaan/adminlist-bundle/EventSubscriber/AdminListSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\AdminListBundle\EventSubscriber;
  3. use Kunstmaan\AdminListBundle\Entity\OverviewNavigationInterface;
  4. use Kunstmaan\NodeBundle\Event\Events;
  5. use Kunstmaan\NodeBundle\Event\NodeEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpFoundation\RedirectResponse;
  8. use Symfony\Component\Routing\RouterInterface;
  9. /**
  10.  * Class AdminListSubscriber.
  11.  */
  12. class AdminListSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * @var RouterInterface
  16.      */
  17.     private $router;
  18.     /**
  19.      * ArticleSubscriber constructor.
  20.      *
  21.      * @param RouterInterface $router
  22.      */
  23.     public function __construct(RouterInterface $router)
  24.     {
  25.         $this->router $router;
  26.     }
  27.     /**
  28.      * @return array
  29.      */
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             Events::POST_DELETE => 'postDelete',
  34.         ];
  35.     }
  36.     /**
  37.      * @param NodeEvent $event
  38.      */
  39.     public function postDelete(NodeEvent $event)
  40.     {
  41.         $page $event->getPage();
  42.         // Redirect to admin list when deleting a page that implements the OverviewNavigationInterface.
  43.         if ($page instanceof OverviewNavigationInterface) {
  44.             $route $this->router->generate($page->getOverViewRoute());
  45.             $response = new RedirectResponse($route);
  46.             $event->setResponse($response);
  47.         }
  48.     }
  49. }