-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathBaseBreadcrumbMenuBlockService.php
135 lines (114 loc) · 3.32 KB
/
BaseBreadcrumbMenuBlockService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\SeoBundle\Block\Breadcrumb;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Knp\Menu\Provider\MenuProviderInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\MenuBlockService;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Abstract class for breadcrumb menu services.
*
* @author Sylvain Deloux <sylvain.deloux@ekino.com>
*/
abstract class BaseBreadcrumbMenuBlockService extends MenuBlockService implements BreadcrumbBlockService
{
/**
* @var string
*/
private $context;
/**
* @var FactoryInterface
*/
private $factory;
/**
* @param string $context
* @param string $name
*/
public function __construct($context, $name, EngineInterface $templating, MenuProviderInterface $menuProvider, FactoryInterface $factory)
{
parent::__construct($name, $templating, $menuProvider);
$this->context = $context;
$this->factory = $factory;
}
/**
* Return true if current BlockService handles the given context.
*
* @param string $context
*
* @return bool
*/
public function handleContext($context)
{
return $this->context === $context;
}
/**
* @deprecated since sonata-project/seo-bundle 2.15, to be removed in 3.0.
*/
public function getName()
{
return sprintf('Breadcrumb %s', $this->context);
}
public function configureSettings(OptionsResolver $resolver)
{
parent::configureSettings($resolver);
$resolver->setDefaults([
'menu_template' => '@SonataSeo/Block/breadcrumb.html.twig',
'include_homepage_link' => true,
'context' => false,
]);
}
/**
* @return FactoryInterface
*
* @final since sonata-project/seo-bundle 2.15
*/
protected function getFactory()
{
return $this->factory;
}
/**
* @return string
*
* @deprecated since sonata-project/seo-bundle 2.15, to be removed in 3.0.
*/
protected function getContext()
{
return $this->context;
}
/**
* Initialize breadcrumb menu.
*
* @return ItemInterface
*
* @deprecated since sonata-project/seo-bundle 2.15, to be removed in 3.0.
*/
protected function getRootMenu(BlockContextInterface $blockContext)
{
$settings = $blockContext->getSettings();
/*
* @todo : Use the router to get the homepage URI
*/
$menu = $this->factory->createItem('breadcrumb');
$menu->setChildrenAttribute('class', 'breadcrumb');
if (method_exists($menu, 'setCurrentUri')) {
$menu->setCurrentUri($settings['current_uri']);
}
$menu->setCurrent(true);
$menu->setUri($settings['current_uri']);
if ($settings['include_homepage_link']) {
$menu->addChild('sonata_seo_homepage_breadcrumb', ['uri' => '/']);
}
return $menu;
}
}