Skip to content

Commit

Permalink
Better way of reordering menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 15, 2024
1 parent 9d5105f commit b012b7f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/EventSubscriber/AddLinkToPeakSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

final class AddLinkToPeakSubscriber implements EventSubscriberInterface
{
private const MENU_ITEM_KEY = 'view_order_in_peak';

public function __construct(private readonly bool $testEnvironment)
{
}
Expand Down Expand Up @@ -41,7 +43,7 @@ public function addLink(OrderShowMenuBuilderEvent $event): void

$menu = $event->getMenu();
$menu
->addChild('view_order_in_peak', [
->addChild(self::MENU_ITEM_KEY, [
'uri' => sprintf('https://app%s.peakwms.com/dialog/orderOverview/%d/details', $this->testEnvironment ? '-test' : '', $peakOrderId),
])
->setAttribute('type', 'link')
Expand All @@ -50,6 +52,12 @@ public function addLink(OrderShowMenuBuilderEvent $event): void
->setLabelAttribute('color', 'blue')
;

$menu->reorderChildren(['view_order_in_peak', 'order_history', 'cancel']);
$sort = array_keys($menu->getChildren());
array_unshift($sort, self::MENU_ITEM_KEY);

try {
$event->getMenu()->reorderChildren($sort);
} catch (\InvalidArgumentException) {
}
}
}

0 comments on commit b012b7f

Please sign in to comment.