Skip to content

Commit

Permalink
Merge branch '1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Apr 18, 2019
2 parents 8d3d74f + 5370682 commit 2b31ab8
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 8 deletions.
57 changes: 57 additions & 0 deletions src/lib/Menu/Admin/ReorderMenuListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,61 @@ public function moveAdminToLast(ConfigureMenuEvent $event): void
$manipulator = new MenuManipulator();
$manipulator->moveToLastPosition($menu[MainMenuBuilder::ITEM_ADMIN]);
}

/**
* @param \EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent $event
*/
public function reorderMenuItems(ConfigureMenuEvent $event): void
{
$menu = $event->getMenu();
$menuOrderArray = [];
$addLast = [];
$alreadyTaken = [];

foreach ($menu->getChildren() as $key => $menuItem) {
if ($menuItem->hasChildren()) {
$this->reorderMenuItems($menuItem);
}
$orderNumber = $menuItem->getExtra('orderNumber');

if ($orderNumber != null) {
if (!isset($menuOrderArray[$orderNumber])) {
$menuOrderArray[$orderNumber] = $menuItem->getName();
} else {
$alreadyTaken[$orderNumber] = $menuItem->getName();
}
} else {
$addLast[] = $menuItem->getName();
}
}
ksort($menuOrderArray);

if (count($alreadyTaken)) {
foreach ($alreadyTaken as $key => $value) {
$keysArray = array_keys($menuOrderArray);
$position = array_search($key, $keysArray);

if ($position === false) {
continue;
}

$menuOrderArray = array_merge(
array_slice($menuOrderArray, 0, $position),
[$value],
array_slice($menuOrderArray, $position)
);
}
}
ksort($menuOrderArray);

if (count($addLast)) {
foreach ($addLast as $key => $value) {
$menuOrderArray[] = $value;
}
}

if (count($menuOrderArray)) {
$menu->reorderChildren($menuOrderArray);
}
}
}
20 changes: 16 additions & 4 deletions src/lib/Menu/ContentCreateRightSidebarBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ public function createStructure(array $options): ItemInterface
'attributes' => $canCreate && $canPublish
? $publishAttributes
: array_merge($publishAttributes, self::BTN_DISABLED_ATTR),
'extras' => ['icon' => 'publish'],
'extras' => [
'icon' => 'publish',
'orderNumber' => 10,
],
]
),
self::ITEM__SAVE_DRAFT => $this->createMenuItem(
Expand All @@ -137,7 +140,10 @@ public function createStructure(array $options): ItemInterface
'attributes' => $canCreate
? $createAttributes
: array_merge($createAttributes, self::BTN_DISABLED_ATTR),
'extras' => ['icon' => 'save'],
'extras' => [
'icon' => 'save',
'orderNumber' => 50,
],
]
),
self::ITEM__PREVIEW => $this->createMenuItem(
Expand All @@ -146,7 +152,10 @@ public function createStructure(array $options): ItemInterface
'attributes' => $canPreview
? $previewAttributes
: array_merge($previewAttributes, self::BTN_DISABLED_ATTR),
'extras' => ['icon' => 'view-desktop'],
'extras' => [
'icon' => 'view-desktop',
'orderNumber' => 60,
],
]
),
self::ITEM__CANCEL => $this->createMenuItem(
Expand All @@ -156,7 +165,10 @@ public function createStructure(array $options): ItemInterface
'class' => self::BTN_TRIGGER_CLASS,
'data-click' => '#ezrepoforms_content_edit_cancel',
],
'extras' => ['icon' => 'circle-close'],
'extras' => [
'icon' => 'circle-close',
'orderNumber' => 70,
],
]
),
]);
Expand Down
20 changes: 16 additions & 4 deletions src/lib/Menu/ContentEditRightSidebarBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ public function createStructure(array $options): ItemInterface
'attributes' => $canEdit && $canPublish
? $publishAttributes
: array_merge($publishAttributes, self::BTN_DISABLED_ATTR),
'extras' => ['icon' => 'publish'],
'extras' => [
'icon' => 'publish',
'orderNumber' => 10,
],
]
),
self::ITEM__SAVE_DRAFT => $this->createMenuItem(
Expand All @@ -130,7 +133,10 @@ public function createStructure(array $options): ItemInterface
'attributes' => $canEdit
? $editAttributes
: array_merge($editAttributes, self::BTN_DISABLED_ATTR),
'extras' => ['icon' => 'save'],
'extras' => [
'icon' => 'save',
'orderNumber' => 50,
],
]
),
];
Expand All @@ -148,7 +154,10 @@ public function createStructure(array $options): ItemInterface
'attributes' => $canDelete
? $deleteAttributes
: array_merge($deleteAttributes, self::BTN_DISABLED_ATTR),
'extras' => ['icon' => 'circle-close'],
'extras' => [
'icon' => 'circle-close',
'orderNumber' => 70,
],
]
);

Expand Down Expand Up @@ -219,7 +228,10 @@ private function getContentPreviewItem(
'attributes' => $canPreview && !empty($siteaccesses)
? $previewAttributes
: array_merge($previewAttributes, self::BTN_DISABLED_ATTR),
'extras' => ['icon' => 'view-desktop'],
'extras' => [
'icon' => 'view-desktop',
'orderNumber' => 60,
],
]
);
}
Expand Down

0 comments on commit 2b31ab8

Please sign in to comment.