LocaleSwitcherListener::onBlock()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

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