Skip to content

Commit 2bb83b8

Browse files
author
roadiz-ci
committed
feat: improve breadcrumb for shadowcontainer and home + refacto duplicate template
1 parent 688d364 commit 2bb83b8

5 files changed

Lines changed: 38 additions & 32 deletions

File tree

src/Controller/Node/NodeDuplicateController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use RZ\Roadiz\CoreBundle\Entity\Node;
99
use RZ\Roadiz\CoreBundle\Event\Node\NodeCreatedEvent;
1010
use RZ\Roadiz\CoreBundle\Event\Node\NodeDuplicatedEvent;
11+
use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface;
1112
use RZ\Roadiz\CoreBundle\Node\NodeDuplicator;
1213
use RZ\Roadiz\CoreBundle\Node\NodeNamePolicyInterface;
1314
use RZ\Roadiz\CoreBundle\Security\Authorization\Voter\NodeVoter;
@@ -18,6 +19,7 @@
1819
use Symfony\Component\HttpFoundation\Response;
1920
use Symfony\Component\HttpKernel\Attribute\AsController;
2021
use Symfony\Component\Routing\Attribute\Route;
22+
use Symfony\Component\String\UnicodeString;
2123
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2224
use Symfony\Contracts\Translation\TranslatorInterface;
2325

@@ -26,6 +28,7 @@ final class NodeDuplicateController extends AbstractController
2628
{
2729
public function __construct(
2830
private readonly NodeNamePolicyInterface $nodeNamePolicy,
31+
private readonly ExplorerItemFactoryInterface $explorerItemFactory,
2932
private readonly ManagerRegistry $managerRegistry,
3033
private readonly EventDispatcherInterface $eventDispatcher,
3134
private readonly TranslatorInterface $translator,
@@ -53,9 +56,17 @@ public function duplicateAction(
5356
$form->handleRequest($request);
5457

5558
if (!$form->isSubmitted() || !$form->isValid()) {
56-
return $this->render('@RoadizRozier/nodes/duplicate.html.twig', [
57-
'node' => $existingNode,
59+
return $this->render('@RoadizRozier/admin/confirm_action.html.twig', [
60+
'title' => new UnicodeString($this->translator->trans('duplicate.node')),
61+
'headPath' => '@RoadizRozier/nodes/head.html.twig',
62+
'cancelPath' => $this->generateUrl('nodesEditPage', ['nodeId' => $existingNode->getId()]),
63+
'alertMessage' => 'are_you_sure.duplicate.node',
64+
'messageType' => 'warning',
65+
'action_color' => 'success',
66+
'action_label' => $this->translator->trans('duplicate'),
67+
'action_icon' => 'rz-icon-ri--file-copy-line',
5868
'form' => $form->createView(),
69+
'items' => [$this->explorerItemFactory->createForEntity($existingNode)->toArray()],
5970
]);
6071
}
6172

templates/macros/rz_page_header.html.twig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,21 @@
6262
{%- if breadcrumbsItem.home -%}
6363
<span class="rz-button__icon rz-icon-ri--home-2-fill"></span>
6464
{%- endif -%}
65+
{% if 'list' in breadcrumbsItem.url %}
66+
<span class="rz-button__icon rz-icon-ri--list-unordered"></span>
67+
{% endif %}
6568
{{- breadcrumbsItem.label|truncate_title -}}
6669
</a>
6770
</li>
6871
{% endif %}
6972
{% endfor %}
7073
<li class="rz-breadcrumb__list-item">
71-
<a href="" class="rz-breadcrumb__item" aria-current="page">{{ breadcrumb.current|truncate_title }}</a>
74+
<a href="" class="rz-breadcrumb__item" aria-current="page">
75+
{%- if breadcrumb.home -%}
76+
<span class="rz-button__icon rz-icon-ri--home-2-fill"></span>
77+
{%- endif -%}
78+
{{ breadcrumb.current|truncate_title }}
79+
</a>
7280
</li>
7381
</ol>
7482
</nav>

templates/nodes/add.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
label: 'nodes-breadcrumb'|trans,
1616
parent: [
1717
{
18-
label: 'nodes'|trans,
18+
label: 'all.nodes'|trans,
1919
type: 'listing',
2020
url: path('nodesHomePage'),
2121
},

templates/nodes/duplicate.html.twig

Lines changed: 0 additions & 26 deletions
This file was deleted.

templates/nodes/head.html.twig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
{% if not source %}
22
{% set source = node.nodeSources.first %}
33
{% endif %}
4+
{% if node.parent.shadow == true %}
5+
{% set breadcrumbParent = [source|parent(null, true)] %}
6+
{% else %}
7+
{% set breadcrumbParent = source|parents(null, true)|reverse %}
8+
{% set homePage = [{
9+
type: 'listing',
10+
url: path('nodesHomePage'),
11+
label: 'all.nodes'|trans,
12+
}] %}
13+
{% set breadcrumbParent = homePage|merge(breadcrumbParent) %}
14+
{% endif %}
15+
416
{% if source is defined and source %}
517
{% set breadcrumb = {
618
'label': 'node-breadcrumb',
7-
'parent': source|parents(null, true)|reverse,
8-
'current': source.title|default(node.nodeName)
19+
'parent': breadcrumbParent,
20+
'current': source.title|default(node.nodeName),
21+
'home': source.node.home,
922
} %}
1023
{% endif %}
1124
{% embed "@RoadizRozier/macros/rz_page_header.html.twig" with {

0 commit comments

Comments
 (0)