vendor/contao-community-alliance/events-contao-bindings/src/Subscribers/BackendSubscriber.php line 89

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     Tristan Lins <tristan.lins@bit3.de>
  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\Backend;
  23. use Contao\CoreBundle\Framework\ContaoFrameworkInterface;
  24. use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents;
  25. use ContaoCommunityAlliance\Contao\Bindings\Events\Backend\AddToUrlEvent;
  26. use ContaoCommunityAlliance\Contao\Bindings\Events\Backend\GetThemeEvent;
  27. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  28. /**
  29.  * Subscriber for the Backend class in Contao.
  30.  */
  31. class BackendSubscriber implements EventSubscriberInterface
  32. {
  33.     /**
  34.      * The contao framework.
  35.      *
  36.      * @var ContaoFrameworkInterface
  37.      */
  38.     protected $framework;
  39.     /**
  40.      * BackendSubscriber constructor.
  41.      *
  42.      * @param ContaoFrameworkInterface $framework The contao framework.
  43.      */
  44.     public function __construct(ContaoFrameworkInterface $framework)
  45.     {
  46.         $this->framework $framework;
  47.     }
  48.     /**
  49.      * Returns an array of event names this subscriber wants to listen to.
  50.      *
  51.      * @return array
  52.      */
  53.     public static function getSubscribedEvents()
  54.     {
  55.         return [
  56.             ContaoEvents::BACKEND_ADD_TO_URL => 'handleAddToUrl',
  57.             ContaoEvents::BACKEND_GET_THEME  => 'handleGetTheme',
  58.         ];
  59.     }
  60.     /**
  61.      * Add some suffix to the current URL.
  62.      *
  63.      * @param AddToUrlEvent $event The event.
  64.      *
  65.      * @return void
  66.      */
  67.     public function handleAddToUrl(AddToUrlEvent $event)
  68.     {
  69.         /** @var Backend $backendAdapter */
  70.         $backendAdapter $this->framework->getAdapter(Backend::class);
  71.         $event->setUrl($backendAdapter->addToUrl($event->getSuffix()));
  72.     }
  73.     /**
  74.      * Add some suffix to the current URL.
  75.      *
  76.      * @param GetThemeEvent $event The event.
  77.      *
  78.      * @return void
  79.      */
  80.     public function handleGetTheme(GetThemeEvent $event)
  81.     {
  82.         /** @var Backend $backendAdapter */
  83.         $backendAdapter $this->framework->getAdapter(Backend::class);
  84.         $event->setTheme($backendAdapter->getTheme());
  85.     }
  86. }