Skip to content

Commit

Permalink
Merge pull request #35 from Setono/fix-reordering
Browse files Browse the repository at this point in the history
Fix possible throwing of exception when reordering menu items
  • Loading branch information
loevgaard authored Aug 15, 2024
2 parents 1cd886f + 001d6f7 commit fc902aa
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/EventSubscriber/OrderShowMenuSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

final class OrderShowMenuSubscriber implements EventSubscriberInterface
{
private const MENU_ITEM_KEY = 'edit';

public static function getSubscribedEvents(): array
{
return [OrderShowMenuBuilder::EVENT_NAME => 'addEditButton'];
Expand All @@ -27,7 +29,7 @@ public function addEditButton(OrderShowMenuBuilderEvent $event): void

$menu
->addChild(
'edit',
self::MENU_ITEM_KEY,
[
'route' => 'sylius_admin_order_update',
'routeParameters' => ['id' => $order->getId()],
Expand All @@ -39,6 +41,12 @@ public function addEditButton(OrderShowMenuBuilderEvent $event): void
->setLabelAttribute('color', 'purple')
;

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

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

0 comments on commit fc902aa

Please sign in to comment.