AbstractMenuContentObject

abstract class \TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject

Generating navigation/menus from TypoScript

The HMENU content object uses this (or more precisely one of the extension classes). Among others the class generates an array of menu items. Thereafter functions from the subclasses are called. The class is always used through extension classes like TextMenuContentObject.

Table of Contents

Constants

customItemStates  : mixed = [ // IFSUB is TRUE if there exist submenu items...

Properties

$parent_cObj  : ContentObjectRenderer
Loaded with the parent cObj-object when a new HMENU is made
$alternativeMenuTempArray  : array
Can be set to contain menu item arrays for sub-levels.
$alwaysActivePIDlist  : int[]
$conf  : array
HMENU configuration
$disableGroupAccessCheck  : bool
$entryLevel  : int
0 = rootFolder
$excludedDoktypes  : int[]
Doktypes that define which should not be included in a menu
$I  : array
$id  : int
The base page-id of the menu.
$mconf  : array
xMENU configuration (TMENU etc)
$menuArr  : array[]
The array of menuItems which is built
$menuContentObjectLocator  : ContainerInterface
$menuNumber  : int
tells you which menu number this is. This is important when getting data from the setup
$MP_array  : string[]
accumulation of mount point data
$nextActive  : string
Holds the page uid of the NEXT page in the root line from the page pointed to by entryLevel; Used to expand the menu automatically if in a certain root line.
$parentMenuArr  : array
$parentMenuArrItemKey  : int|null
Array key of the parentMenuItem in the parentMenuArr, if this menu is a subMenu.
$request  : ServerRequestInterface
$result  : array
$rL_uidRegister  : array|null
Is filled with an array of page uid numbers + RL parameters which are in the current root line (used to evaluate whether a menu item is in active state)
$sys_page  : PageRepository

Methods

__construct()  : mixed
filterMenuPages()  : bool
Checks if a page is OK to include in the final menu item array. Pages can be excluded if the doktype is wrong, if they are hidden in navigation, have a uid in the list of banned uids etc.
generate()  : mixed
Calls processItemStates() so that the common configuration for the menu items are resolved into individual configuration per item.
getMenuItems()  : array<int, array{data: array, title: string, link: string, target: string, active: int, current: int, spacer: int, hasSubpages?: int, children?: array}>
Returns menu items as a structured array instead of rendered HTML.
getParentContentObject()  : ContentObjectRenderer
Returns the parent content object
getParentMenuArr()  : array
Get the parentMenuArr, if this is subMenu.
getParentMenuItem()  : array|null
Get the parentMenuItem from the parentMenuArr, if this is a subMenu
getSysPage()  : PageRepository
Returns the sys_page object
makeMenu()  : mixed
Creates the menu in the internal variables, ready for output.
setParentMenu()  : void
Set the parentMenuArr and key to provide the parentMenu information to the subMenu, special fur IProcFunc and itemArrayProcFunc user functions.
start()  : bool
The initialization of the object. This just sets some internal variables.
writeMenu()  : string
buildPageRepository()  : PageRepository
Builds PageRepository instance without depending on global context, e.g.
createMenuContentObject()  : AbstractMenuContentObject|null
Creates the menu content object for a TypoScript menu type like "TMENU", or NULL if no menu content object is registered for that type.
createPageObject()  : RecordInterface
getBannedUids()  : array
Returns an array of banned UIDs (from excludeUidList)
getCache()  : FrontendInterface
getCacheIdentifierForSubMenuDecision()  : string
getCurrentLanguageAspect()  : LanguageAspect
getCurrentSite()  : Site
getDoktypeExcludeWhere()  : string
Returns where clause part to exclude 'not in menu' pages
getMPvar()  : string
Return MPvar string for entry $key in ->menuArr
getPageTitle()  : string
Returns the title for the navigation
getRuntimeCache()  : FrontendInterface
getSubMenuItems()  : array
Get submenu items as array (recursive helper for getMenuItems)
getTimeTracker()  : TimeTracker
hasParentMenuArr()  : bool
Check if there is a valid parentMenuArr.
hasParentMenuItem()  : bool
Check if the parentMenuItem exists
hasParentMenuItemKey()  : bool
Check if we have a parentMenuArrItemKey
isActive()  : bool
Returns TRUE if the given page is active (in the current rootline)
isCurrent()  : bool
Returns TRUE if the page is the CURRENT page.
isItemState()  : bool
Used by processItemStates() to evaluate if a menu item (identified by $key) is in a certain state.
isNext()  : bool
Returns TRUE if the page with UID $uid is the NEXT page in root line (which means a submenu should be drawn)
isRootLineAccessible()  : bool
Checks whether a page in the rootline blocks the given page through extendToSubpages, which is what denies the request of a page in the frontend as well.
isSubMenu()  : bool
Returns TRUE if there is a submenu with items for the page id, $uid Used by the item states "IFSUB", "ACTIFSUB" and "CURIFSUB" to check if there is a submenu
link()  : LinkResultInterface|null
Creates the URL, target and data-window-* attributes for the menu item link. Returns them in an array as key/value pairs for <A>-tag attributes
menuTypoLink()  : LinkResultInterface
Calls typolink to create menu item links.
prepareMenuItems()  : array
Main function for retrieving menu items based on the menu type (special or sectionIndex or "normal")
prepareMenuItemsForBrowseMenu()  : array
Fetches all menuitems if special = browse is set
prepareMenuItemsForDirectoryMenu()  : array
Fetches all menuitems if special = directory is set
prepareMenuItemsForKeywordsMenu()  : array
Fetches all menuitems if special = keywords is set
prepareMenuItemsForLanguageMenu()  : array
Fetches all menuitems if special = language is set
prepareMenuItemsForListMenu()  : array
Fetches all menuitems if special = list is set
prepareMenuItemsForRootlineMenu()  : array
Fetches all menuitems if special = rootline is set
prepareMenuItemsForUpdatedMenu()  : array
Fetches all menuitems if special = updated is set
prepareMenuItemsForUserSpecificMenu()  : array
Fetches all menuitems if special = userfunction is set
processItemStates()  : array
Generating the per-menu-item configuration arrays based on the settings for item states (NO, ACT, CUR etc) set in ->mconf (config for the current menu object) Basically it will produce an individual array for each menu item based on the item states.
removeInaccessiblePages()  : array
Gets an array of page rows and removes all, which are not accessible
sectionIndex()  : array
Generates a list of content objects with sectionIndex enabled available on a specific page
setATagParts()  : mixed
Creates the <A> tag parts for the current item (in $this->I, [A1] and [A2]) based on the given link result
subMenu()  : string
Creates a submenu level to the current level - if configured for.
userProcess()  : mixed
Calls a user function for processing of internal data.

Constants

customItemStates

protected mixed customItemStates = [ // IFSUB is TRUE if there exist submenu items to the c…
Show the full value[ // IFSUB is TRUE if there exist submenu items to the current item 'IFSUB', 'ACT', // ACTIFSUB is TRUE if there exist submenu items to the current item and the current item is active 'ACTIFSUB', // CUR is TRUE if the current page equals the item here! 'CUR', // CURIFSUB is TRUE if there exist submenu items to the current item and the current page equals the item here! 'CURIFSUB', 'USR', 'SPC', 'USERDEF1', 'USERDEF2', ]

Properties

$alternativeMenuTempArray

Can be set to contain menu item arrays for sub-levels.

protected array $alternativeMenuTempArray = []

$alwaysActivePIDlist

protected int[] $alwaysActivePIDlist = []

$conf

HMENU configuration

protected array $conf = []

$disableGroupAccessCheck

protected bool $disableGroupAccessCheck = false

$entryLevel

0 = rootFolder

protected int $entryLevel = 0

$excludedDoktypes

Doktypes that define which should not be included in a menu

protected int[] $excludedDoktypes = [\TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_B…
Show the full value[\TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_BE_USER_SECTION, \TYPO3\CMS\Core\Domain\Repository\PageRepository::DOKTYPE_SYSFOLDER]

$id

The base page-id of the menu.

protected int $id = 0

$mconf

xMENU configuration (TMENU etc)

protected array $mconf = []

$menuArr

The array of menuItems which is built

protected array[] $menuArr = []

$menuContentObjectLocator read-only

protected ContainerInterface $menuContentObjectLocator

$menuNumber

tells you which menu number this is. This is important when getting data from the setup

protected int $menuNumber = 1

$MP_array

accumulation of mount point data

protected string[] $MP_array = []

$nextActive

Holds the page uid of the NEXT page in the root line from the page pointed to by entryLevel; Used to expand the menu automatically if in a certain root line.

protected string $nextActive = ''

$parentMenuArr

protected array $parentMenuArr = []

$parentMenuArrItemKey

Array key of the parentMenuItem in the parentMenuArr, if this menu is a subMenu.

protected int|null $parentMenuArrItemKey = null

$request

protected ServerRequestInterface $request

$rL_uidRegister

Is filled with an array of page uid numbers + RL parameters which are in the current root line (used to evaluate whether a menu item is in active state)

protected array|null $rL_uidRegister = null

Methods

__construct()

public __construct(ContainerInterface $menuContentObjectLocator) : mixed

Parameters

$menuContentObjectLocator : ContainerInterface

Locator of all menu content objects registered via the "frontend.menucontentobject" tag, keyed by their (upper cased) TypoScript identifier. Used to create the menu objects of the next level.

filterMenuPages()

Checks if a page is OK to include in the final menu item array. Pages can be excluded if the doktype is wrong, if they are hidden in navigation, have a uid in the list of banned uids etc.

public filterMenuPages(array &$data, array $banUidArray, bool $isSpacerPage) : bool

Parameters

$data : array

Array of menu items

$banUidArray : array

Array of page uids which are to be excluded

$isSpacerPage : bool

If set, then the page is a spacer.

Tags

throws
UnexpectedValueException

Return values

bool —

Returns TRUE if the page can be safely included.

generate()

Calls processItemStates() so that the common configuration for the menu items are resolved into individual configuration per item.

public generate() : mixed

Sets the result for the new "normal state" in $this->result

Tags

see
AbstractMenuContentObject::processItemStates()

getMenuItems()

Returns menu items as a structured array instead of rendered HTML.

public getMenuItems() : array<int, array{data: array, title: string, link: string, target: string, active: int, current: int, spacer: int, hasSubpages?: int, children?: array}>

This provides direct access to menu data without rendering overhead.

Return values

array<int, array{data: array, title: string, link: string, target: string, active: int, current: int, spacer: int, hasSubpages?: int, children?: array}>

getParentMenuArr()

Get the parentMenuArr, if this is subMenu.

public getParentMenuArr() : array

Return values

array

getParentMenuItem()

Get the parentMenuItem from the parentMenuArr, if this is a subMenu

public getParentMenuItem() : array|null

Return values

array|null

makeMenu()

Creates the menu in the internal variables, ready for output.

public makeMenu() : mixed

Basically this will read the page records needed and fill in the internal $this->menuArr Based on a hash of this array and some other variables the $this->result variable will be loaded either from cache OR by calling the generate() method of the class to create the menu for real.

setParentMenu()

Set the parentMenuArr and key to provide the parentMenu information to the subMenu, special fur IProcFunc and itemArrayProcFunc user functions.

public setParentMenu(array $menuArr, int $menuItemKey) : void

Parameters

$menuArr : array
$menuItemKey : int

start()

The initialization of the object. This just sets some internal variables.

public start(null $_, PageRepository $sys_page, int|string $id, array $conf, int $menuNumber, string $objSuffix, ServerRequestInterface $request) : bool

Parameters

$_ : null

Obsolete argument

$sys_page : PageRepository
$id : int|string

A starting point page id. This should probably be blank since the 'entryLevel' value will be used then.

$conf : array

The TypoScript configuration for the HMENU cObject

$menuNumber : int

Menu number; 1,2,3. Should probably be 1

$objSuffix : string

Submenu Object suffix. This offers submenus a way to use alternative configuration for specific positions in the menu; By default "1 = TMENU" would use "1." for the TMENU configuration, but if this string is set to eg. "a" then "1a." would be used for configuration instead (while "1 = " is still used for the overall object definition of "TMENU")

$request : ServerRequestInterface

Tags

see
ContentObjectRenderer::HMENU()

Return values

bool —

Returns TRUE on success

writeMenu()

public writeMenu() : string

Return values

string —

The HTML for the menu

buildPageRepository()

Builds PageRepository instance without depending on global context, e.g.

protected buildPageRepository([LanguageAspect|null $languageAspect = null ]) : PageRepository

not automatically overlaying records based on current request language.

Parameters

$languageAspect : LanguageAspect|null = null

Return values

PageRepository

createMenuContentObject()

Creates the menu content object for a TypoScript menu type like "TMENU", or NULL if no menu content object is registered for that type.

protected createMenuContentObject(string $menuType) : AbstractMenuContentObject|null

Parameters

$menuType : string

Return values

AbstractMenuContentObject|null

getBannedUids()

Returns an array of banned UIDs (from excludeUidList)

protected getBannedUids() : array

Return values

array —

Array of banned UIDs

getCacheIdentifierForSubMenuDecision()

protected getCacheIdentifierForSubMenuDecision(mixed $uid) : string

Parameters

$uid : mixed

Return values

string

getDoktypeExcludeWhere()

Returns where clause part to exclude 'not in menu' pages

protected getDoktypeExcludeWhere() : string

Return values

string —

where clause part.

getMPvar()

Return MPvar string for entry $key in ->menuArr

protected getMPvar(int $key) : string

Parameters

$key : int

Pointer to element in ->menuArr

Tags

see
link()

Return values

string —

MP vars for element.

getPageTitle()

Returns the title for the navigation

protected getPageTitle(string $title, string $nav_title) : string

Parameters

$title : string

The current page title

$nav_title : string

The current value of the navigation title

Return values

string —

Returns the navigation title if it is NOT blank, otherwise the page title.

getSubMenuItems()

Get submenu items as array (recursive helper for getMenuItems)

protected getSubMenuItems(int $uid, int $menuItemKey) : array

Parameters

$uid : int
$menuItemKey : int

Return values

array

hasParentMenuArr()

Check if there is a valid parentMenuArr.

protected hasParentMenuArr() : bool

Return values

bool

hasParentMenuItem()

Check if the parentMenuItem exists

protected hasParentMenuItem() : bool

Return values

bool

hasParentMenuItemKey()

Check if we have a parentMenuArrItemKey

protected hasParentMenuItemKey() : bool

Return values

bool

isActive()

Returns TRUE if the given page is active (in the current rootline)

protected isActive(array $page, string $MPvar) : bool

Parameters

$page : array

Page record to evaluate.

$MPvar : string

MPvar for the current position of item.

Return values

bool —

TRUE if $page is active

isCurrent()

Returns TRUE if the page is the CURRENT page.

protected isCurrent(array $page, string $MPvar) : bool

Parameters

$page : array

Page record to evaluate.

$MPvar : string

MPvar for the current position of item.

Return values

bool —

TRUE if resolved page ID is current requested page id

isItemState()

Used by processItemStates() to evaluate if a menu item (identified by $key) is in a certain state.

protected isItemState(string $kind, int $key) : bool

Parameters

$kind : string

The item state to evaluate (SPC, IFSUB, ACT etc...)

$key : int

Key pointing to menu item from ->menuArr

Tags

see
processItemStates()

Return values

bool —

Returns TRUE if state matches

isNext()

Returns TRUE if the page with UID $uid is the NEXT page in root line (which means a submenu should be drawn)

protected isNext(int $uid, string $MPvar) : bool

Parameters

$uid : int

Page uid to evaluate.

$MPvar : string

MPvar for the current position of item.

Tags

see
subMenu()

Return values

bool —

TRUE if page with $uid is active

isRootLineAccessible()

Checks whether a page in the rootline blocks the given page through extendToSubpages, which is what denies the request of a page in the frontend as well.

protected isRootLineAccessible(int $pageId) : bool

Parameters

$pageId : int

Return values

bool

isSubMenu()

Returns TRUE if there is a submenu with items for the page id, $uid Used by the item states "IFSUB", "ACTIFSUB" and "CURIFSUB" to check if there is a submenu

protected isSubMenu(int $uid) : bool

Parameters

$uid : int

Page uid for which to search for a submenu

Return values

bool —

Returns TRUE if there was a submenu with items found

Creates the URL, target and data-window-* attributes for the menu item link. Returns them in an array as key/value pairs for <A>-tag attributes

protected link(int $key, string $altTarget, string $typeOverride) : LinkResultInterface|null

Parameters

$key : int

Pointer to a key in the $this->menuArr array where the value for that key represents the menu item we are linking to (page record)

$altTarget : string

Alternative target

$typeOverride : string

Alternative type

Return values

LinkResultInterface|null

Calls typolink to create menu item links.

protected menuTypoLink(array $page, string $oTarget, string $addParams, int|string $typeOverride[, int|null $overridePageId = null ]) : LinkResultInterface

Parameters

$page : array

Page record (uid points where to link to)

$oTarget : string

Target frame/window

$addParams : string

Parameters to add to URL

$typeOverride : int|string

"type" value, empty string means "not set"

$overridePageId : int|null = null

link to this page instead of the $page[uid] value

Return values

LinkResultInterface

prepareMenuItems()

Main function for retrieving menu items based on the menu type (special or sectionIndex or "normal")

protected prepareMenuItems() : array

Return values

array

prepareMenuItemsForBrowseMenu()

Fetches all menuitems if special = browse is set

protected prepareMenuItemsForBrowseMenu(string $specialValue, string $sortingField, string $additionalWhere) : array

Parameters

$specialValue : string

The value from special.value

$sortingField : string

The sorting field

$additionalWhere : string

Additional WHERE clause

Return values

array

prepareMenuItemsForDirectoryMenu()

Fetches all menuitems if special = directory is set

protected prepareMenuItemsForDirectoryMenu(string $specialValue, string $sortingField) : array

Parameters

$specialValue : string

The value from special.value

$sortingField : string

The sorting field

Return values

array

prepareMenuItemsForKeywordsMenu()

Fetches all menuitems if special = keywords is set

protected prepareMenuItemsForKeywordsMenu(string $specialValue, string $sortingField) : array

Parameters

$specialValue : string

The value from special.value

$sortingField : string

The sorting field

Return values

array

prepareMenuItemsForLanguageMenu()

Fetches all menuitems if special = language is set

protected prepareMenuItemsForLanguageMenu(string $specialValue) : array

Parameters

$specialValue : string

The value from special.value

Return values

array

prepareMenuItemsForListMenu()

Fetches all menuitems if special = list is set

protected prepareMenuItemsForListMenu(string $specialValue) : array

Parameters

$specialValue : string

The value from special.value

Return values

array

prepareMenuItemsForRootlineMenu()

Fetches all menuitems if special = rootline is set

protected prepareMenuItemsForRootlineMenu() : array

Return values

array

prepareMenuItemsForUpdatedMenu()

Fetches all menuitems if special = updated is set

protected prepareMenuItemsForUpdatedMenu(string $specialValue, string $sortingField) : array

Parameters

$specialValue : string

The value from special.value

$sortingField : string

The sorting field

Return values

array

prepareMenuItemsForUserSpecificMenu()

Fetches all menuitems if special = userfunction is set

protected prepareMenuItemsForUserSpecificMenu(string $specialValue, string $sortingField) : array

Parameters

$specialValue : string

The value from special.value

$sortingField : string

The sorting field

Return values

array

processItemStates()

Generating the per-menu-item configuration arrays based on the settings for item states (NO, ACT, CUR etc) set in ->mconf (config for the current menu object) Basically it will produce an individual array for each menu item based on the item states.

protected processItemStates(int $splitCount) : array

BUT in addition the "optionSplit" syntax for the values is ALSO evaluated here so that all property-values are "option-splitted" and the output will thus be resolved. Is called from the "generate" functions in the extension classes. The function is processor intensive due to the option split feature in particular. But since the generate function is not always called (since the ->result array may be cached, see makeMenu) it doesn't hurt so badly.

Parameters

$splitCount : int

Number of menu items in the menu

Return values

array —

the resolved configuration for each item

removeInaccessiblePages()

Gets an array of page rows and removes all, which are not accessible

protected removeInaccessiblePages(array $pages) : array

Parameters

$pages : array

Return values

array

sectionIndex()

Generates a list of content objects with sectionIndex enabled available on a specific page

protected sectionIndex(string $altSortField[, int $pid = null ]) : array

Used for menus with sectionIndex enabled

Parameters

$altSortField : string

Alternative sorting field

$pid : int = null

The page id to search for sections

Tags

throws
UnexpectedValueException

if the query to fetch the content elements unexpectedly fails

Return values

array

setATagParts()

Creates the <A> tag parts for the current item (in $this->I, [A1] and [A2]) based on the given link result

protected setATagParts(LinkResultInterface|null $linkResult) : mixed

Parameters

$linkResult : LinkResultInterface|null

subMenu()

Creates a submenu level to the current level - if configured for.

protected subMenu(int $uid, string $objSuffix, int $menuItemKey) : string

Parameters

$uid : int

Page id of the current page for which a submenu MAY be produced (if conditions are met)

$objSuffix : string

Object prefix, see ->start()

$menuItemKey : int

Return values

string —

HTML content of the submenu

userProcess()

Calls a user function for processing of internal data.

protected userProcess(string $mConfKey, mixed $passVar) : mixed

Used for the properties "IProcFunc" and "itemArrayProcFunc"

Parameters

$mConfKey : string

Key pointing for the property in the current ->mconf array holding possibly parameters to pass along to the function/method. Currently the keys used are "IProcFunc" and "itemArrayProcFunc".

$passVar : mixed

A variable to pass to the user function and which should be returned again from the user function. The idea is that the user function modifies this variable according to what you want to achieve and then returns it. For "itemArrayProcFunc" this variable is $this->menuArr, for "IProcFunc" it is $this->I

Return values

mixed —

The processed $passVar

On this page