Skip to content

Commit

Permalink
[TASK] Fully deprecate and ignore showHidden on menus
Browse files Browse the repository at this point in the history
Field is a core enableField which should be respected. The PageRepository is being used and can (if we decide so in the future) be prepped to show hidden pages *if a BE user is logged in* or depending on other ENV.
  • Loading branch information
NamelessCoder committed Apr 26, 2014
1 parent e41bf57 commit ce1513e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
23 changes: 5 additions & 18 deletions Classes/Service/PageSelectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ class Tx_Vhs_Service_PageSelectService implements \TYPO3\CMS\Core\SingletonInter
*/
protected static $pageSelect;

/**
* @var \TYPO3\CMS\Frontend\Page\PageRepository
*/
protected static $pageSelectHidden;

/**
* @var array
*/
Expand All @@ -71,23 +66,20 @@ class Tx_Vhs_Service_PageSelectService implements \TYPO3\CMS\Core\SingletonInter
* Initialize \TYPO3\CMS\Frontend\Page\PageRepository objects
*/
public function initializeObject() {
self::$pageSelect = $this->createPageSelectInstance(FALSE);
self::$pageSelectHidden = $this->createPageSelectInstance(TRUE);
self::$pageSelect = $this->createPageSelectInstance();
}

/**
* @param boolean $showHidden
* @return \TYPO3\CMS\Frontend\Page\PageRepository
*/
private function createPageSelectInstance($showHidden = FALSE) {
private function createPageSelectInstance() {
if (TRUE === is_array($GLOBALS['TSFE']->fe_user->user)) {
$groups = array(-2, 0);
$groups = array_merge($groups, (array) array_values($GLOBALS['TSFE']->fe_user->groupData['uid']));
} else {
$groups = array(-1, 0);
}
$pageSelect = new \TYPO3\CMS\Frontend\Page\PageRepository();
$pageSelect->init((boolean) $showHidden);
$clauses = array();
foreach ($groups as $group) {
$clause = "fe_group = '" . $group . "' OR fe_group LIKE '" .
Expand Down Expand Up @@ -135,14 +127,13 @@ public function getPageOverlay($pageInput, $languageUid = -1) {
* Caution: different signature
*
* @param integer $pageUid
* @param boolean $showHidden
* @param array $excludePages
* @param string $where
* @param boolean $showHiddenInMenu
* @param boolean $checkShortcuts
* @return array
*/
public function getMenu($pageUid = NULL, $showHidden = FALSE, $excludePages = array(), $where = '', $showHiddenInMenu = FALSE, $checkShortcuts = FALSE) {
public function getMenu($pageUid = NULL, $excludePages = array(), $where = '', $showHiddenInMenu = FALSE, $checkShortcuts = FALSE) {
if (NULL === $pageUid) {
$pageUid = $GLOBALS['TSFE']->id;
}
Expand All @@ -156,13 +147,9 @@ public function getMenu($pageUid = NULL, $showHidden = FALSE, $excludePages = ar
if ('' !== $where) {
$addWhere = $where . ' ' . $addWhere;
}
$key = md5(intval($showHidden) . $pageUid . $addWhere . intval($checkShortcuts));
$key = md5(intval($showHiddenInMenu) . $pageUid . $addWhere . intval($checkShortcuts));
if (FALSE === isset(self::$cachedMenus[$key])) {
if (TRUE === $showHidden) {
self::$cachedMenus[$key] = self::$pageSelectHidden->getMenu($pageUid, '*', 'sorting', $addWhere, $checkShortcuts);
} else {
self::$cachedMenus[$key] = self::$pageSelect->getMenu($pageUid, '*', 'sorting', $addWhere, $checkShortcuts);
}
self::$cachedMenus[$key] = self::$pageSelect->getMenu($pageUid, '*', 'sorting', $addWhere, $checkShortcuts);
}
return self::$cachedMenus[$key];
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/If/Page/HasSubpagesViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function render($pageUid = NULL, $includeHidden = FALSE, $showHiddenInMen
if (NULL === $pageUid || TRUE === empty($pageUid) || 0 === intval($pageUid)) {
$pageUid = $GLOBALS['TSFE']->id;
}
$menu = $this->pageSelect->getMenu($pageUid, (boolean) $includeHidden, array(), '', $showHiddenInMenu);
$menu = $this->pageSelect->getMenu($pageUid, array(), '', $showHiddenInMenu);
$pageHasSubPages = (0 < count($menu));
if (TRUE === $pageHasSubPages) {
return $this->renderThenChild();
Expand Down
13 changes: 3 additions & 10 deletions Classes/ViewHelpers/Page/Menu/AbstractMenuViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function initializeArguments() {
$this->registerArgument('substElementUid', 'boolean', 'Optional parameter for wrapping the link with the uid of the page', FALSE, '');
$this->registerArgument('includeSpacers', 'boolean', 'Wether or not to include menu spacers in the page select query', FALSE, FALSE);
$this->registerArgument('resolveExclude', 'boolean', 'Exclude link if realurl/cooluri flag tx_realurl_exclude is set', FALSE, FALSE);
$this->registerArgument('showHidden', 'boolean', 'Include disabled pages into the menu', FALSE, FALSE);
$this->registerArgument('showHidden', 'boolean', 'DEPRECATED - IGNORED. FIELD IS AN ENABLE-FIELD WHICH MUST BE RESPECTED. Include disabled pages into the menu', FALSE, FALSE);
$this->registerArgument('showHiddenInMenu', 'boolean', 'Include pages that are set to be hidden in menus', FALSE, FALSE);
$this->registerArgument('showCurrent', 'boolean', 'If FALSE, does not display the current page', FALSE, TRUE);
$this->registerArgument('linkCurrent', 'boolean', 'If FALSE, does not wrap the current page in a link', FALSE, TRUE);
Expand Down Expand Up @@ -459,21 +459,14 @@ protected function parseMenu($menu, $rootLine) {
$filtered = array();
$allowedDocumentTypes = $this->allowedDoktypeList();
foreach ($menu as $page) {
if (TRUE === (boolean) $page['hidden']) {
continue;
} elseif (TRUE === (boolean) $page['nav_hide'] && FALSE === (boolean) $this->arguments['showHidden']) {
continue;
} elseif (TRUE === isset($page['tx_realurl_exclude']) && TRUE === (boolean) $page['tx_realurl_exclude'] && TRUE === (boolean) $this->arguments['resolveExclude']) {
if (TRUE === isset($page['tx_realurl_exclude']) && TRUE === (boolean) $page['tx_realurl_exclude'] && TRUE === (boolean) $this->arguments['resolveExclude']) {
continue;
} elseif (TRUE === isset($page['tx_cooluri_exclude']) && TRUE === (boolean) $page['tx_cooluri_exclude'] && TRUE === (boolean) $this->arguments['resolveExclude']) {
continue;
} elseif (TRUE === $this->pageSelect->hidePageForLanguageUid($page['uid'], $GLOBALS['TSFE']->sys_language_uid)) {
continue;
} elseif (TRUE === in_array($page['doktype'], $allowedDocumentTypes)) {
$page = $this->getMenuItemEntry($page, $rootLine);
if (TRUE === (boolean) $page['nav_hide'] && FALSE === (boolean) $this->arguments['showHidden']) {
continue;
}
$filtered[$page['uid']] = $page;
}
}
Expand Down Expand Up @@ -685,7 +678,7 @@ public function getMenu($pageUid, $where = '') {
$excludePages = $this->processPagesArgument($this->arguments['excludePages']);
$showHidden = (boolean) $this->arguments['showHidden'];
$showHiddenInMenu = (boolean) $this->arguments['showHiddenInMenu'];
$menuData = $this->pageSelect->getMenu($pageUid, $showHidden, $excludePages, $where, $showHiddenInMenu, FALSE);
$menuData = $this->pageSelect->getMenu($pageUid, $excludePages, $where, $showHiddenInMenu, FALSE);
return $menuData;
}

Expand Down

2 comments on commit ce1513e

@bjo3rnf
Copy link
Contributor

@bjo3rnf bjo3rnf commented on ce1513e May 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean it's become a global setting for all menus? If so I don't like it ;)

@NamelessCoder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is now global for all menus to exclude hidden pages. As mentioned in the commit message we can still decide on conditions which would render hidden pages, but it has to be respected that "hidden" means "cannot load that record in FE" (the only exception being in "preview" modes with a BE user logged in, possibly even toggled by a flag which when active, also disables page caching).

The right flag to use is nav_hide which is not an enableField. We should respect TYPO3's hidden flag ;)

Please sign in to comment.