vendor/contao-community-alliance/events-contao-bindings/src/Subscribers/FrontendSubscriber.php line 72

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of contao-community-alliance/events-contao-bindings
  4.  *
  5.  * (c) 2014-2018 The Contao Community Alliance
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  *
  10.  * This project is provided in good faith and hope to be usable by anyone.
  11.  *
  12.  * @package    ContaoCommunityAlliance\Contao\Bindings
  13.  * @subpackage Subscribers
  14.  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  15.  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  16.  * @author     Sven Baumann <baumann.sv@gmail.com>
  17.  * @copyright  2018 The Contao Community Alliance.
  18.  * @license    https://github.com/contao-community-alliance/events-contao-bindings/blob/master/LICENSE LGPL-3.0
  19.  * @filesource
  20.  */
  21. namespace ContaoCommunityAlliance\Contao\Bindings\Subscribers;
  22. use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
  23. use Contao\Frontend;
  24. use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents;
  25. use ContaoCommunityAlliance\Contao\Bindings\Events\Frontend\AddToUrlEvent;
  26. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  27. /**
  28.  * Subscriber for the Backend class in Contao.
  29.  */
  30. class FrontendSubscriber implements EventSubscriberInterface
  31. {
  32.     /**
  33.      * The contao framework.
  34.      *
  35.      * @var ContaoFrameworkInterface
  36.      */
  37.     protected $framework;
  38.     /**
  39.      * FrontendSubscriber constructor.
  40.      *
  41.      * @param ContaoFrameworkInterface $framework The contao framework.
  42.      */
  43.     public function __construct(ContaoFrameworkInterface $framework)
  44.     {
  45.         $this->framework $framework;
  46.     }
  47.     /**
  48.      * Returns an array of event names this subscriber wants to listen to.
  49.      *
  50.      * @return array
  51.      */
  52.     public static function getSubscribedEvents()
  53.     {
  54.         return [
  55.             ContaoEvents::FRONTEND_ADD_TO_URL => 'handleAddToUrl'
  56.         ];
  57.     }
  58.     /**
  59.      * Add some suffix to the current URL.
  60.      *
  61.      * @param AddToUrlEvent $event The event.
  62.      *
  63.      * @return void
  64.      */
  65.     public function handleAddToUrl(AddToUrlEvent $event)
  66.     {
  67.         /** @var Frontend $frontendAdapter */
  68.         $frontendAdapter $this->framework->getAdapter(Frontend::class);
  69.         $event->setUrl($frontendAdapter->addToUrl($event->getSuffix(), $event->isIgnoreParams()));
  70.     }
  71. }