Skip to content

Commit

Permalink
Include children and drafts in allowed pages
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainjule committed Feb 23, 2022
1 parent 1a6e407 commit 9c2a624
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions lib/bouncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@

class Bouncer {

private static function getChildren($allowed, Kirby\Cms\Page $page) {
if (!$page->hasChildren()) {
return [];
}

$allowed = [];
$pages = $page->childrenAndDrafts();
foreach($pages as $p) {
$allowed[] = [
'title' => $p->title()->value(),
'path' => $p->panelUrl(true)
];


$children = Bouncer::getChildren($allowed, $p);
$allowed = array_merge($allowed, $children);
}

return $allowed;
}

public static function getAllowedPages($user, $fieldname, $extra = false) {
$kirby = kirby();
$allowed = [];
Expand All @@ -37,8 +16,8 @@ public static function getAllowedPages($user, $fieldname, $extra = false) {
'path' => $page->panelUrl(true)
];

$children = $extra ? Bouncer::getChildren($allowed, $page) : [];
$allowed = array_merge($allowed, $children);
$children = $extra ? static::getChildren($page) : [];
$allowed = array_merge($allowed, $children);
}
}

Expand All @@ -56,4 +35,23 @@ public static function getAllowedPages($user, $fieldname, $extra = false) {
return $allowed;
}

private static function getChildren(Kirby\Cms\Page $page) {
if (!($page->hasChildren() || $page->hasDrafts())) { return []; }

$allowed = [];
$pages = $page->childrenAndDrafts();

foreach($pages as $p) {
$allowed[] = [
'title' => $p->title()->value(),
'path' => $p->panelUrl(true)
];

$children = static::getChildren($p);
$allowed = array_merge($allowed, $children);
}

return $allowed;
}

}

0 comments on commit 9c2a624

Please sign in to comment.