2021-09-07 15:51:21 +02:00
|
|
|
<?php
|
|
|
|
$seed = 'sb-' . mt_rand();
|
|
|
|
$icon = $parent['icon'] ?? '';
|
|
|
|
$label = $parent['label'] ?? '';
|
|
|
|
$children = $parent['children'] ?? [];
|
2021-09-10 15:37:20 +02:00
|
|
|
$active = false;
|
|
|
|
|
2021-09-07 15:51:21 +02:00
|
|
|
if (!empty($children)) {
|
|
|
|
$url = "#{$seed}";
|
|
|
|
} else {
|
|
|
|
$url = $parent['url'] ?? '#';
|
|
|
|
}
|
2021-09-10 15:37:20 +02:00
|
|
|
|
|
|
|
$controller = \Cake\Utility\Inflector::variable($this->request->getParam('controller'));
|
|
|
|
$action = \Cake\Utility\Inflector::variable($this->request->getParam('action'));
|
|
|
|
$currentURL = "/{$controller}/{$action}";
|
|
|
|
if ($url == $currentURL) {
|
|
|
|
$active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$hasActiveChild = false;
|
|
|
|
if (!empty($children)) {
|
|
|
|
$flattened = Cake\Utility\Hash::flatten($children);
|
|
|
|
$flattenedValues = array_values($flattened);
|
|
|
|
if (in_array($currentURL, $flattenedValues)) {
|
|
|
|
$hasActiveChild = true;
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 15:51:21 +02:00
|
|
|
?>
|
|
|
|
|
|
|
|
<li class="<?= !empty($children) ? 'parent collapsed' : '' ?>">
|
2021-09-17 13:04:37 +02:00
|
|
|
<a class="sidebar-link <?= !empty($children) ? 'collapsed' : '' ?> <?= $active ? 'active' : '' ?> <?= $hasActiveChild ? 'have-active-child' : '' ?>" href="<?= h($url) ?>" <?= !empty($children) ? 'data-bs-toggle="collapse"' : '' ?> <?= $hasActiveChild ? 'aria-expanded="true"' : '' ?>>
|
2021-09-07 15:51:21 +02:00
|
|
|
<i class="sidebar-icon <?= $this->FontAwesome->getClass($icon) ?>"></i>
|
|
|
|
<span class="text"><?= h($label) ?></span>
|
|
|
|
</a>
|
|
|
|
<?php if (!empty($children)): ?>
|
|
|
|
<?= $this->element('layouts/sidebar/sub-menu', [
|
|
|
|
'seed' => $seed,
|
|
|
|
'children' => $children,
|
2021-09-10 15:37:20 +02:00
|
|
|
'open' => $hasActiveChild
|
2021-09-07 15:51:21 +02:00
|
|
|
]);
|
|
|
|
?>
|
|
|
|
<?php endif; ?>
|
2021-09-10 15:37:20 +02:00
|
|
|
</li>
|