vendor/sonata-project/translation-bundle/src/EventListener/LocaleSwitcherListener.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <[email protected]>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\TranslationBundle\EventListener;
  12. use Sonata\BlockBundle\Event\BlockEvent;
  13. use Sonata\BlockBundle\Model\Block;
  14. /**
  15.  * @author Nicolas Bastien <[email protected]>
  16.  */
  17. class LocaleSwitcherListener
  18. {
  19.     public function onBlock(BlockEvent $event$eventName)
  20.     {
  21.         $settings $event->getSettings();
  22.         if ('sonata.block.event.sonata.admin.show.top' === $eventName) {
  23.             $settings['locale_switcher_route'] = 'show';
  24.         }
  25.         if ('sonata.block.event.sonata.admin.list.table.top' === $eventName) {
  26.             $settings['locale_switcher_route'] = 'list';
  27.         }
  28.         $block = new Block();
  29.         $block->setSettings($settings);
  30.         $block->setName('sonata_translation.block.locale_switcher');
  31.         $block->setType('sonata_translation.block.locale_switcher');
  32.         $event->addBlock($block);
  33.     }
  34. }