Skip to content

Commit

Permalink
Make tabs management independent
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Pichat committed Aug 23, 2023
1 parent d178af6 commit f8e566d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 35 deletions.
1 change: 0 additions & 1 deletion admin-dev/themes/new-theme/template/layout.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
table=$table
help_link=$help_link
enableSidebar=$enableSidebar
tabs=$tabs
use_regular_h1_structure=$use_regular_h1_structure
}
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,22 @@
</div>
{% endif %}

{% if currentTabLevel is same as 3 %}
{% if currentTabLevel >= 3 %}
<div class="page-head-tabs" id="head_tabs">
<ul class="nav nav-pills">
{% for level_1 in tabs %}
{% for level_2 in level_1.sub_tabs %}
{% for level_3 in level_2.sub_tabs %}
{% if level_3.current %}
{% for level_4 in level_3.sub_tabs %}
{% if level_4.active %}
<li class="nav-item">
<a href="{{ level_4.href }}" id="subtab-{{ level_4.class_name }}"
class="nav-link tab {% if level_4.current %}active current{% endif %}"
data-submenu="{{ level_4.id_tab }}">
{{ level_4.name }}
<span class="notification-container">
<span class="notification-counter"></span>
</span>
</a>
</li>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}
{% for tab in navigationTabs %}
{% if tab.attributes.active %}
<li class="nav-item">
<a href="{{ tab.href }}" id="subtab-{{ tab.attributes.class_name }}"
class="nav-link tab {% if tab.attributes.current %}active current{% endif %}"
data-submenu="{{ tab.attributes.id_tab }}">
{{ tab.name }}
<span class="notification-container">
<span class="notification-counter"></span>
</span>
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
table: table,
helpLink: help_link,
enableSidebar: enableSidebar,
tabs: tabs,
useRegularH1Structure: use_regular_h1_structure
}) }}
12 changes: 8 additions & 4 deletions src/PrestaShopBundle/Twig/Component/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Toolbar
public bool|string $helpLink;
public bool $enableSidebar;
public int $currentTabLevel = 0;
public array $tabs;
public array $navigationTabs = [];
public array $breadcrumbs;
public bool $useRegularH1Structure = true;

Expand All @@ -64,10 +64,14 @@ public function mount(): void
if (!empty($ancestorsTab)) {
$tabs[] = $ancestorsTab;
$this->currentTabLevel = count($ancestorsTab);
}

$this->breadcrumbs = $this->menuBuilder->convertTabsToBreadcrumbLinks($tab, $ancestorsTab);
$this->hookDispatcher->dispatchWithParameters('actionAdminBreadcrumbModifier', ['tabs' => $tabs, 'breadcrumb' => &$this->breadcrumbs]);
if ($this->currentTabLevel >= 3) {
$this->navigationTabs = $this->menuBuilder->buildNavigationTabs($tab);
}

$this->breadcrumbs = $this->menuBuilder->convertTabsToBreadcrumbLinks($tab, $ancestorsTab);
$this->hookDispatcher->dispatchWithParameters('actionAdminBreadcrumbModifier', ['tabs' => $tabs, 'breadcrumb' => &$this->breadcrumbs]);
}
}
}
}
45 changes: 38 additions & 7 deletions src/PrestaShopBundle/Twig/Layout/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,40 @@ public function convertTabsToBreadcrumbLinks(Tab $currentTab, array $tabAncestor

private function convertTabToMenuLink(Tab $tab): MenuLink
{
if (!empty($tab->getRouteName())) {
$href = $this->urlGenerator->generate($tab->getRouteName());
} else {
$href = $this->context->getAdminLink($tab->getClassName());
}

return new MenuLink(
name: $this->getBreadcrumbLabel($tab),
href: $href,
href: $this->getLinkFromTab($tab),
icon: 'icon-' . $tab->getClassName(),
);
}

/**
* @return array<int, MenuLink>
*/
public function buildNavigationTabs(Tab $tab): array
{
$currentLevelTabs = $this->tabRepository->findByParentId($tab->getIdParent());
$navigationTabs = [];

/* @var $currentLevelTab Tab */
foreach ($currentLevelTabs as $currentLevelTab) {
$menuLink = new MenuLink(
name: $currentLevelTab->getWording(),
href: $this->getLinkFromTab($currentLevelTab),
attributes: [
'id_tab' => $currentLevelTab->getId(),
'class_name' => $currentLevelTab->getClassName(),
'current' => $currentLevelTab->getId() == $tab->getId(),
'active' => $currentLevelTab->getActive(),
]
);
$navigationTabs[] = $menuLink;
}

return $navigationTabs;
}


private function getBreadcrumbLabel(Tab $tab): string
{
if (null !== $tab->getWording() && null !== $tab->getWordingDomain()) {
Expand Down Expand Up @@ -198,4 +219,14 @@ private function getLegacyControllerClassName(): ?string
{
return $this->requestStack->getMainRequest()->attributes->get('_legacy_controller');
}

private function getLinkFromTab(Tab $tab): string
{
if (!empty($tab->getRouteName())) {
$href = $this->urlGenerator->generate($tab->getRouteName());
} else {
$href = $this->context->getAdminLink($tab->getClassName());
}
return $href;
}
}

0 comments on commit f8e566d

Please sign in to comment.