Skip to content

Commit 916387c

Browse files
committed
Fix: Undefined array key
1 parent ad66045 commit 916387c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Menu/MenuBuilder.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(FactoryInterface $factory, RequestStack $requestStac
5050

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

@@ -81,7 +81,7 @@ public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null,
8181

8282
$_groups = StringUtil::deserialize($page->groups, true);
8383

84-
if (!$options['showProtected'] && ($page->protected && !\count(array_intersect($_groups, $groups)))) {
84+
if (!($options['showProtected'] ?? false) && ($page->protected && !\count(array_intersect($_groups, $groups)))) {
8585
continue;
8686
}
8787

@@ -93,9 +93,9 @@ public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null,
9393
$item->setDisplayChildren(false);
9494

9595
if (
96-
!$options['showLevel'] || $options['showLevel'] >= $level ||
96+
!($options['showLevel'] ?? 0) || ($options['showLevel'] ?? 0) >= $level ||
9797
(
98-
!$options['hardLimit'] && ($requestPage->id === $page->id || \in_array($requestPage->id, $childRecords, true))
98+
!($options['hardLimit'] ?? 0) && ($requestPage->id === $page->id || \in_array($requestPage->id, $childRecords, true))
9999
)
100100
) {
101101
$item->setDisplayChildren(true);
@@ -145,12 +145,12 @@ public function getMenu(ItemInterface $root, int $pid, $level = 1, $host = null,
145145

146146
private function getPages(int $pid, array $options): ?Collection
147147
{
148-
if ('customnav' !== $options['type']) {
148+
if ('customnav' !== ($options['type'] ?? '')) {
149149
$time = Date::floorToMinute();
150150
$beUserLoggedIn = $this->tokenChecker->isPreviewMode();
151151
$unroutableTypes = $this->pageRegistry->getUnroutableTypes();
152152

153-
$arrPages = Database::getInstance()->prepare("SELECT p1.*, EXISTS(SELECT * FROM tl_page p2 WHERE p2.pid=p1.id AND p2.type!='root' AND p2.type NOT IN ('".implode("', '", $unroutableTypes)."')".(!$options['showHidden'] ? ' AND p2.hide=0' : '').(!$beUserLoggedIn ? " AND p2.published=1 AND (p2.start='' OR p2.start<=$time) AND (p2.stop='' OR p2.stop>$time)" : '').") AS subpages FROM tl_page p1 WHERE p1.pid=? AND p1.type!='root' AND p1.type NOT IN ('".implode("', '", $unroutableTypes)."')".(!$options['showHidden'] ? ' AND p1.hide=0' : '').(!$beUserLoggedIn ? " AND p1.published=1 AND (p1.start='' OR p1.start<=$time) AND (p1.stop='' OR p1.stop>$time)" : '').' ORDER BY p1.sorting')
153+
$arrPages = Database::getInstance()->prepare("SELECT p1.*, EXISTS(SELECT * FROM tl_page p2 WHERE p2.pid=p1.id AND p2.type!='root' AND p2.type NOT IN ('".implode("', '", $unroutableTypes)."')".(!($options['showHidden'] ?? false) ? ' AND p2.hide=0' : '').(!$beUserLoggedIn ? " AND p2.published=1 AND (p2.start='' OR p2.start<=$time) AND (p2.stop='' OR p2.stop>$time)" : '').") AS subpages FROM tl_page p1 WHERE p1.pid=? AND p1.type!='root' AND p1.type NOT IN ('".implode("', '", $unroutableTypes)."')".(!($options['showHidden'] ?? false) ? ' AND p1.hide=0' : '').(!$beUserLoggedIn ? " AND p1.published=1 AND (p1.start='' OR p1.start<=$time) AND (p1.stop='' OR p1.stop>$time)" : '').' ORDER BY p1.sorting')
154154
->execute($pid)
155155
;
156156

@@ -161,7 +161,7 @@ private function getPages(int $pid, array $options): ?Collection
161161
return Collection::createFromDbResult($arrPages, 'tl_page');
162162
}
163163

164-
$ids = StringUtil::deserialize($options['pages'], true);
164+
$ids = StringUtil::deserialize(($options['pages'] ?? ''), true);
165165

166166
if (method_exists(PageModel::class, 'findPublishedRegularWithoutGuestsByIds')) {
167167
return PageModel::findPublishedRegularWithoutGuestsByIds($ids, ['includeRoot' => true]);

0 commit comments

Comments
 (0)