Skip to content

Commit bba510f

Browse files
authored
allow brick group sort behaviour (#227)
* allow brick group sort behaviour * adjust docs
1 parent 6b352ae commit bba510f

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The Toolbox is a Kickstarter for your every day project. It provides some import
2525

2626
```json
2727
"require" : {
28-
"dachcom-digital/toolbox" : "~5.0.0"
28+
"dachcom-digital/toolbox" : "~5.2.0"
2929
}
3030
```
3131

UPGRADE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 5.2.0
44
- [NEW FEATURE] Add element hash to headless stack
5+
- [NEW FEATURE] Allow manual brick group sorting [#225](https://github.com/dachcom-digital/pimcore-toolbox/issues/225)
56

67
## 5.1.2
78
- [BUGFIX] Enriched injected JS `toolbox-wysiwyg-document-style.js` with toolbox document id param [#223](https://github.com/dachcom-digital/pimcore-toolbox/issues/223)

docs/0_Usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ area_block_configuration:
6666
groups:
6767
-
6868
name: Project
69+
# optional, set sorting to "manually" to respect given order, otherwise sorting will be alphabetically
70+
sorting: !php/const ToolboxBundle\Manager\AreaManagerInterface::BRICK_GROUP_SORTING_MANUALLY
6971
elements:
7072
- your_custom_area_brick
7173

src/Manager/AreaManager.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,31 @@ public function getAreaBlockConfiguration(?string $type, bool $fromSnippet = fal
5555
$cleanedGroups = [];
5656
$cleanedGroupsSorted = [];
5757

58-
foreach ($groups as $groupName => $groupData) {
58+
foreach ($groups as $groupData) {
5959
$groupName = $groupData['name'];
6060
$cleanedGroup = [];
6161

62+
$sorting = $groupData['sorting'] ?? self::BRICK_GROUP_SORTING_ALPHABETICALLY;
63+
6264
foreach ($groupData['elements'] as $element) {
6365
if (in_array($element, $availableBricks['allowed'], true)) {
6466
$cleanedGroup[] = $element;
6567
}
6668
}
6769

68-
//ok, group elements found, add them
6970
if (count($cleanedGroup) > 0) {
7071
$cleanedGroups[$groupName] = $cleanedGroup;
71-
$cleanedGroupsSorted = array_merge($cleanedGroupsSorted, $cleanedGroup);
72-
//sort group by cleaned group
73-
sort($cleanedGroupsSorted);
72+
73+
if ($sorting === self::BRICK_GROUP_SORTING_ALPHABETICALLY) {
74+
sort($cleanedGroup);
75+
}
76+
77+
$cleanedGroupsSorted[] = $cleanedGroup;
7478
}
7579
}
7680

7781
if (count($cleanedGroups) > 0) {
78-
$configuration['sorting'] = $cleanedGroupsSorted;
82+
$configuration['sorting'] = array_merge([], ...$cleanedGroupsSorted);
7983
$configuration['group'] = $cleanedGroups;
8084
}
8185

src/Manager/AreaManagerInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
interface AreaManagerInterface
66
{
7+
public const BRICK_GROUP_SORTING_ALPHABETICALLY = 'alphabetically';
8+
public const BRICK_GROUP_SORTING_MANUALLY = 'manually';
9+
710
public function getAreaBlockName(?string $type = null): string;
811

912
/**

0 commit comments

Comments
 (0)