/
DashboardStacksBreadcrumbFactory.php
116 lines (103 loc) · 4.29 KB
/
DashboardStacksBreadcrumbFactory.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
<?php
namespace Concrete\Core\Navigation\Breadcrumb\Dashboard;
use Concrete\Core\Application\ApplicationAwareInterface;
use Concrete\Core\Application\ApplicationAwareTrait;
use Concrete\Core\Html\Service\Navigation;
use Concrete\Core\Multilingual\Service\UserInterface\Flag;
use Concrete\Core\Navigation\Breadcrumb\BreadcrumbInterface;
use Concrete\Core\Navigation\Item\Item;
use Concrete\Core\Page\Page;
use Concrete\Core\Page\Stack\Folder\Folder;
use Concrete\Core\Page\Stack\Stack;
class DashboardStacksBreadcrumbFactory implements ApplicationAwareInterface
{
use ApplicationAwareTrait;
/**
* @var DashboardBreadcrumbFactory
*/
protected $breadcrumbFactory;
/**
* @var Navigation
*/
protected $navigation;
/**
* @var bool
*/
protected $displayGlobalAreasLandingPage = false;
/**
* @param bool $displayGlobalAreasLandingPage
*/
public function setDisplayGlobalAreasLandingPage(bool $displayGlobalAreasLandingPage): void
{
$this->displayGlobalAreasLandingPage = $displayGlobalAreasLandingPage;
}
public function __construct(DashboardBreadcrumbFactory $breadcrumbFactory, Navigation $navigation)
{
$this->breadcrumbFactory = $breadcrumbFactory;
$this->navigation = $navigation;
}
public function getBreadcrumb(Page $dashboardPage, $stackOrFolder = null, array $sections = null, $locale = ''): BreadcrumbInterface
{
$breadcrumb = $this->breadcrumbFactory->getBreadcrumb($dashboardPage);
if ($this->displayGlobalAreasLandingPage) {
$breadcrumb->add(new Item(
$this->app->make('url')->to('/dashboard/blocks/stacks', 'view_global_areas'),
t('Global Areas')
));
}
if ($stackOrFolder) {
if ($stackOrFolder instanceof Folder) {
$stackOrFolder = $stackOrFolder->getPage();
}
$stacks = array_reverse($this->navigation->getTrailToCollection($stackOrFolder));
array_shift($stacks); // Remove the top "Stacks" page.
$stacks[] = $stackOrFolder;
foreach($stacks as $stack) {
$stackItem = new Item(
$this->app->make('url')->to(
'/dashboard/blocks/stacks', 'view_details', $stack->getCollectionID()
),
$stack->getCollectionName()
);
$breadcrumb->add($stackItem);
}
if ($stackOrFolder instanceof Stack) {
// let's handle the breadcrumb dropdown for localized stacks
if ($stackOrFolder->isNeutralStack()) {
$neutralStack = $stackOrFolder;
} else {
$neutralStack = $stackOrFolder->getNeutralStack();
}
$children = [
new Item(
$this->app->make('url')->to(
'/dashboard/blocks/stacks', 'view_details', $neutralStack->getCollectionID()
),
'<strong>' . h(tc('Locale', 'Default Content')) . '</strong>',
$locale === ''
)
];
foreach ($sections as $sectionLocale => $section) {
/* @var Section $section */
$localizedStackName = Flag::getSectionFlagIcon($section) . ' ' . h($section->getLanguageText());
if ($neutralStack->getLocalizedStack($section) !== null) {
$localizedStackName = '<strong>' . $localizedStackName . '</strong>';
}
$children[] = new Item(
$this->app->make('url')->to(
'/dashboard/blocks/stacks', 'view_details',
$neutralStack->getCollectionID() . rawurlencode('@' . $sectionLocale
)
),
$localizedStackName . ' <span class="text-muted">' . h($sectionLocale) . '</span>',
$locale === $sectionLocale
);
}
foreach($children as $child) {
$stackItem->addChild($child);
}
}
}
return $breadcrumb;
}
}