|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\CoreBundle\Block; |
|
5
|
|
|
|
|
6
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
7
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
|
8
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
9
|
|
|
use Sonata\SeoBundle\Block\Breadcrumb\BaseBreadcrumbMenuBlockService; |
|
10
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class BreadcrumbBlockService |
|
14
|
|
|
* @package Chamilo\CoreBundle\Block |
|
15
|
|
|
*/ |
|
16
|
|
|
class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService |
|
17
|
|
|
{ |
|
18
|
|
|
protected $extraChildren; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritdoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getName() |
|
24
|
|
|
{ |
|
25
|
|
|
return 'chamilo_core.block.breadcrumb'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function configureSettings(OptionsResolver $resolver) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::configureSettings($resolver); |
|
34
|
|
|
|
|
35
|
|
|
$resolver->setDefaults(array( |
|
36
|
|
|
'menu_template' => 'SonataSeoBundle:Block:breadcrumb.html.twig', |
|
37
|
|
|
'include_homepage_link' => false, |
|
38
|
|
|
'context' => false, |
|
39
|
|
|
)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param string $title |
|
44
|
|
|
* @param array $params |
|
45
|
|
|
*/ |
|
46
|
|
|
public function addChild($title, $params = []) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->extraChildren[] = ['title' => $title, 'params' => $params]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function getMenu(BlockContextInterface $blockContext) |
|
55
|
|
|
{ |
|
56
|
|
|
$menu = $this->getRootMenu($blockContext); |
|
57
|
|
|
|
|
58
|
|
|
$menu->addChild('Home', ['route' => 'home']); |
|
59
|
|
|
|
|
60
|
|
|
// Add course |
|
61
|
|
|
/** @var Course $course */ |
|
62
|
|
|
if ($course = $blockContext->getBlock()->getSetting('course')) { |
|
63
|
|
|
$menu->addChild( |
|
64
|
|
|
$course->getTitle(), |
|
65
|
|
|
array( |
|
66
|
|
|
'route' => 'course_home', |
|
67
|
|
|
'routeParameters' => array( |
|
68
|
|
|
'course' => $course->getCode(), |
|
69
|
|
|
), |
|
70
|
|
|
) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (!empty($this->extraChildren)) { |
|
75
|
|
|
foreach ($this->extraChildren as $item) { |
|
76
|
|
|
$params = isset($item['params']) ? $item['params'] : []; |
|
77
|
|
|
$menu->addChild( |
|
78
|
|
|
$item['title'], |
|
79
|
|
|
$params |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// Load legacy breadcrumbs |
|
85
|
|
|
$oldBreadCrumb = $blockContext->getBlock()->getSetting( |
|
86
|
|
|
'legacy_breadcrumb' |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
if ($oldBreadCrumb) { |
|
90
|
|
|
foreach ($oldBreadCrumb as $data) { |
|
91
|
|
|
if (empty($data['name'])) { |
|
92
|
|
|
continue; |
|
93
|
|
|
} |
|
94
|
|
|
$url = $data['url']; |
|
95
|
|
|
if ($url == '#') { |
|
96
|
|
|
$menu->addChild($data['name']); |
|
97
|
|
|
} else { |
|
98
|
|
|
$menu->addChild($data['name'], ['uri' => $url]); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $menu; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|