[BUGFIX] Correctly handle non-existing level in menu.directory VH 67/54167/2
authorMarkus Klein <markus.klein@typo3.org>
Tue, 19 Sep 2017 10:23:56 +0000 (12:23 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 19 Sep 2017 12:20:15 +0000 (14:20 +0200)
Providing a non-existing entry-level to the getPageUids() method
now returns an empty array instead of an array with key zero and
a null value.

This way we can correctly stop processing in the viewhelpers
using the MenuViewHelperTrait.

Resolves: #82507
Releases: 7.6
Change-Id: I99a610e612545648d7637e4a441dcdd1b1e51adc
Reviewed-on: https://review.typo3.org/54167
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Tested-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/DirectoryViewHelper.php
typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/ListViewHelper.php
typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/MenuViewHelperTrait.php

index edc5e2e..a8466b2 100644 (file)
@@ -72,6 +72,10 @@ class DirectoryViewHelper extends AbstractViewHelper
         $includeMenuSeparator = (bool)$this->arguments['includeMenuSeparator'];
 
         $pageUids = $this->getPageUids($pageUids, $entryLevel);
+        if (empty($pageUids)) {
+            return '';
+        }
+
         $pages = $typoScriptFrontendController->sys_page->getMenu(
             $pageUids,
             '*',
index 779f2a0..3f066c7 100644 (file)
@@ -69,6 +69,10 @@ class ListViewHelper extends AbstractViewHelper
         $includeMenuSeparator = (bool)$this->arguments['includeMenuSeparator'];
 
         $pageUids = $this->getPageUids($pageUids, $entryLevel);
+        if (empty($pageUids)) {
+            return '';
+        }
+
         $pages = $typoScriptFrontendController->sys_page->getMenuForPages(
             $pageUids,
             '*',
index 175931d..76a2dcd 100644 (file)
@@ -72,18 +72,21 @@ trait MenuViewHelperTrait
         $pageUids = array_filter($pageUids);
 
         // If no pages have been defined, use the current page
-        if (empty($pageUids)) {
-            if ($entryLevel !== null) {
-                if ($entryLevel < 0) {
-                    $entryLevel = count($typoScriptFrontendController->tmpl->rootLine) - 1 + $entryLevel;
-                }
-                $pageUids = [$typoScriptFrontendController->tmpl->rootLine[$entryLevel]['uid']];
-            } else {
-                $pageUids = [$typoScriptFrontendController->id];
-            }
+        if (!empty($pageUids)) {
+            return $pageUids;
         }
 
-        return $pageUids;
+        if ($entryLevel === null) {
+            return [$typoScriptFrontendController->id];
+        }
+
+        if ($entryLevel < 0) {
+            $entryLevel = count($typoScriptFrontendController->tmpl->rootLine) - 1 + $entryLevel;
+        }
+        if (isset($typoScriptFrontendController->tmpl->rootLine[$entryLevel]['uid'])) {
+            return [$typoScriptFrontendController->tmpl->rootLine[$entryLevel]['uid']];
+        }
+        return [];
     }
 
     /**