Skip to content

Commit

Permalink
allow brick group sort behaviour (#227)
Browse files Browse the repository at this point in the history
* allow brick group sort behaviour

* adjust docs
  • Loading branch information
solverat authored Aug 15, 2024
1 parent 6b352ae commit bba510f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The Toolbox is a Kickstarter for your every day project. It provides some import

```json
"require" : {
"dachcom-digital/toolbox" : "~5.0.0"
"dachcom-digital/toolbox" : "~5.2.0"
}
```

Expand Down
1 change: 1 addition & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

## 5.1.2
- [BUGFIX] Enriched injected JS `toolbox-wysiwyg-document-style.js` with toolbox document id param [#223](https://github.com/dachcom-digital/pimcore-toolbox/issues/223)
Expand Down
2 changes: 2 additions & 0 deletions docs/0_Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ area_block_configuration:
groups:
-
name: Project
# optional, set sorting to "manually" to respect given order, otherwise sorting will be alphabetically
sorting: !php/const ToolboxBundle\Manager\AreaManagerInterface::BRICK_GROUP_SORTING_MANUALLY
elements:
- your_custom_area_brick
Expand Down
16 changes: 10 additions & 6 deletions src/Manager/AreaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,31 @@ public function getAreaBlockConfiguration(?string $type, bool $fromSnippet = fal
$cleanedGroups = [];
$cleanedGroupsSorted = [];

foreach ($groups as $groupName => $groupData) {
foreach ($groups as $groupData) {
$groupName = $groupData['name'];
$cleanedGroup = [];

$sorting = $groupData['sorting'] ?? self::BRICK_GROUP_SORTING_ALPHABETICALLY;

foreach ($groupData['elements'] as $element) {
if (in_array($element, $availableBricks['allowed'], true)) {
$cleanedGroup[] = $element;
}
}

//ok, group elements found, add them
if (count($cleanedGroup) > 0) {
$cleanedGroups[$groupName] = $cleanedGroup;
$cleanedGroupsSorted = array_merge($cleanedGroupsSorted, $cleanedGroup);
//sort group by cleaned group
sort($cleanedGroupsSorted);

if ($sorting === self::BRICK_GROUP_SORTING_ALPHABETICALLY) {
sort($cleanedGroup);
}

$cleanedGroupsSorted[] = $cleanedGroup;
}
}

if (count($cleanedGroups) > 0) {
$configuration['sorting'] = $cleanedGroupsSorted;
$configuration['sorting'] = array_merge([], ...$cleanedGroupsSorted);
$configuration['group'] = $cleanedGroups;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Manager/AreaManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

interface AreaManagerInterface
{
public const BRICK_GROUP_SORTING_ALPHABETICALLY = 'alphabetically';
public const BRICK_GROUP_SORTING_MANUALLY = 'manually';

public function getAreaBlockName(?string $type = null): string;

/**
Expand Down

0 comments on commit bba510f

Please sign in to comment.