Completed
Push — 3.x ( 733455...aa9981 )
by Grégoire
02:00
created

NewsArchiveBreadcrumbBlockService::getMenu()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
cc 3
nc 4
nop 1
1
<?php
2
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
12
namespace Sonata\NewsBundle\Block\Breadcrumb;
13
14
use Sonata\BlockBundle\Block\BlockContextInterface;
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
17
/**
18
 * BlockService for archive breadcrumb.
19
 *
20
 * @author Sylvain Deloux <[email protected]>
21
 */
22
class NewsArchiveBreadcrumbBlockService extends BaseNewsBreadcrumbBlockService
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getName()
28
    {
29
        return 'sonata.news.block.breadcrumb_archive';
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function configureSettings(OptionsResolver $resolver)
36
    {
37
        parent::configureSettings($resolver);
38
39
        $resolver->setDefaults([
40
            'collection' => false,
41
            'tag' => false,
42
        ]);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function getMenu(BlockContextInterface $blockContext)
49
    {
50
        $menu = $this->getRootMenu($blockContext);
51
52
        if ($collection = $blockContext->getBlock()->getSetting('collection')) {
53
            $menu->addChild($collection->getName(), [
54
                'route' => 'sonata_news_collection',
55
                'routeParameters' => [
56
                    'collection' => $collection->getSlug(),
57
                ],
58
                'extras' => [
59
                    'translation_domain' => false,
60
                ],
61
            ]);
62
        }
63
64
        if ($tag = $blockContext->getBlock()->getSetting('tag')) {
65
            $menu->addChild($tag->getName(), [
66
                'route' => 'sonata_news_tag',
67
                'routeParameters' => [
68
                    'tag' => $tag->getSlug(),
69
                ],
70
                'extras' => [
71
                    'translation_domain' => false,
72
                ],
73
            ]);
74
        }
75
76
        return $menu;
77
    }
78
}
79