LocaleSwitcherListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A onBlock() 0 17 3
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