Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow brick group sort behaviour #227

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading