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\NewsBundle\Block\Breadcrumb; |
15
|
|
|
|
16
|
|
|
use Knp\Menu\FactoryInterface; |
17
|
|
|
use Knp\Menu\Provider\MenuProviderInterface; |
18
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
19
|
|
|
use Sonata\NewsBundle\Model\BlogInterface; |
20
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
21
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* BlockService for post breadcrumb. |
25
|
|
|
* |
26
|
|
|
* @author Sylvain Deloux <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class NewsPostBreadcrumbBlockService extends BaseNewsBreadcrumbBlockService |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var BlogInterface |
32
|
|
|
*/ |
33
|
|
|
protected $blog; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $context |
37
|
|
|
* @param string $name |
38
|
|
|
*/ |
39
|
|
|
public function __construct($context, $name, EngineInterface $templating, MenuProviderInterface $menuProvider, FactoryInterface $factory, BlogInterface $blog) |
40
|
|
|
{ |
41
|
|
|
$this->blog = $blog; |
42
|
|
|
|
43
|
|
|
parent::__construct($context, $name, $templating, $menuProvider, $factory); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getName() |
47
|
|
|
{ |
48
|
|
|
return 'sonata.news.block.breadcrumb_post'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function configureSettings(OptionsResolver $resolver): void |
52
|
|
|
{ |
53
|
|
|
parent::configureSettings($resolver); |
54
|
|
|
|
55
|
|
|
$resolver->setDefaults([ |
56
|
|
|
'post' => false, |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function getMenu(BlockContextInterface $blockContext) |
61
|
|
|
{ |
62
|
|
|
$menu = $this->getRootMenu($blockContext); |
63
|
|
|
|
64
|
|
|
if ($post = $blockContext->getBlock()->getSetting('post')) { |
65
|
|
|
$menu->addChild($post->getTitle(), [ |
66
|
|
|
'route' => 'sonata_news_view', |
67
|
|
|
'routeParameters' => [ |
68
|
|
|
'permalink' => $this->blog->getPermalinkGenerator()->generate($post), |
69
|
|
|
], |
70
|
|
|
'extras' => [ |
71
|
|
|
'translation_domain' => false, |
72
|
|
|
], |
73
|
|
|
]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $menu; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|