Skip to content

Commit

Permalink
Merge pull request #6688 from getkirby/fix/6684-tree-parent-request
Browse files Browse the repository at this point in the history
Fix page tree parents request
  • Loading branch information
bastianallgeier authored Sep 20, 2024
2 parents 9f41476 + c3437b1 commit bab1682
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
13 changes: 10 additions & 3 deletions config/areas/site/requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@
'action' => function () {
$kirby = App::instance();
$request = $kirby->request();
$root = $request->get('root');
$page = $kirby->page($request->get('page'));
$parents = $page?->parents()->flip()->values(
fn ($parent) => $parent->uuid()?->toString() ?? $parent->id()
) ?? [];

// if root is included, add the site as top-level parent
if ($root === 'true') {
array_unshift($parents, $kirby->site()->uuid()?->toString() ?? '/');
}

return [
'data' => $page->parents()->flip()->values(
fn ($parent) => $parent->uuid()?->toString() ?? $parent->id()
)
'data' => $parents
];
}
]
Expand Down
22 changes: 15 additions & 7 deletions panel/src/components/Navigation/PageTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export default {
});
},
async open(item) {
if (!item) {
return;
}
if (item.hasChildren === false) {
return false;
}
Expand All @@ -79,30 +83,34 @@ export default {
// get array of parent uuids/ids
const response = await this.$panel.get("site/tree/parents", {
query: {
page
page,
root: this.root
}
});
const parents = response.data;
// if root is included, add the site as top-level parent
if (this.root) {
parents.unshift("site://");
}
let tree = this;
// go through all parents, try to find the matching item,
// open it and pass forward the pointer to that tree component
for (let index = 0; index < parents.length; index++) {
const value = parents[index];
const item = tree.findItem(value);
if (!item) {
return;
}
await this.open(item);
tree = tree.$refs[value][0];
}
// find current page in deepest tree and trigger select listeners
const item = tree.findItem(page);
this.$emit("select", item);
if (item) {
this.$emit("select", item);
}
}
}
};
Expand Down

0 comments on commit bab1682

Please sign in to comment.