Skip to content

Commit

Permalink
feat: Sync sort order with folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
philippoehrlein committed Dec 5, 2024
1 parent 02824d9 commit d75d484
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kirby Navigation Groups
![License](https://img.shields.io/badge/license-MIT-green)
![Version](https://img.shields.io/badge/version-1.0.6-blue)
![Version](https://img.shields.io/badge/version-1.1.0-blue)

A plugin for Kirby CMS that allows you to organize your navigation items into groups.

Expand All @@ -10,6 +10,7 @@ A plugin for Kirby CMS that allows you to organize your navigation items into gr

- Create and manage navigation groups
- Drag & drop interface for organizing pages
- Sync sort order with folder structure
- Multi-language support (EN, DE, FR, ES, IT)
- Customizable group fields

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A Kirby Plugin for grouping navigation items",
"type": "kirby-plugin",
"license": "MIT",
"version": "1.0.6",
"version": "1.1.0",
"homepage": "https://github.com/philippoehrlein/kirby-navigation-groups",
"authors": [
{
Expand Down
21 changes: 21 additions & 0 deletions config/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@
}
],
'save' => function ($value = null) {
if ($value) {
$sortedPages = [];
foreach ($value as $item) {
if ($item['type'] === 'page') {
$sortedPages[] = $item['id'];
} else if ($item['type'] === 'group' && isset($item['pages'])) {
foreach ($item['pages'] as $page) {
$sortedPages[] = $page['id'];
}
}
}

foreach ($sortedPages as $index => $pageId) {
if ($page = page($pageId)) {
if ($page->isWritable()) {
$page->changeSort($index + 1);
}
}
}
}

return Yaml::encode($value);
},
],
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
'api' => require __DIR__ . '/config/api.php',
'translations' => require __DIR__ . '/config/translations.php',
'fieldMethods' => require __DIR__ . '/config/fieldMethods.php',
'version' => '1.0.6'
'version' => '1.1.0'
]);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "kirby-navigation-groups",
"version": "1.0.6",
"version": "1.1.0",
"author": {
"name": "Philipp Oehrlein",
"email": "[email protected]"
Expand Down

0 comments on commit d75d484

Please sign in to comment.