Skip to content

Commit

Permalink
Pass options to submenus + harden against invalid access (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-vo authored Feb 16, 2021
1 parent 96809b1 commit 5e0f727
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Menu/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function __construct(

public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null, array $options = []): ItemInterface
{
if (empty($options) || null === ($pages = $this->getPages($pid, $options))) {
return $root;
}

$groups = [];
$request = $this->requestStack->getCurrentRequest();
$requestPage = $request->attributes->get('pageModel');
Expand All @@ -60,10 +64,6 @@ public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null,
$groups = $user->groups;
}

if (null === ($pages = $this->getPages($pid, $options))) {
return $root;
}

foreach ($pages as $page) {
$item = new MenuItem($page->title, $this->factory);

Expand All @@ -80,7 +80,7 @@ public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null,

// Check whether there will be subpages
if ($page->subpages > 0) {
$this->getMenu($item, (int) $page->id, $level++, $host);
$this->getMenu($item, (int) $page->id, $level++, $host, $options);

$childRecords = Database::getInstance()->getChildRecords($page->id, 'tl_page');
if (!$options['showLevel']
Expand Down

0 comments on commit 5e0f727

Please sign in to comment.