#109501Menu returns no children if subpages are of type Link (doktype=3) only
Description
Pages of type Link (doktype=3) are not rendered as submenu children when they are the only child pages of a parent page. The `children` array is empty. If at least one regular page exists alongside the Link pages, all pages (including Links) appear correctly.
Steps to Reproduce
- Create a page tree:
Site Root Page
└── Menu Item (standard page)
├── Link page 1 (doktype=3)
└── Link page 2 (doktype=3)
- Render a menu using `MenuProcessor`:
10 = menu
10 {
levels = 2
as = testMenu
}
Result: Menu Item page appears in the menu, but its children array is empty.
*Expected:* Link pages appear as children.
Adding one regular page alongside the Link pages makes all of them appear, including the Links.
Root Cause
`isSubMenu()` in `AbstractMenuContentObject` fetches child pages in a batch query to determine whether a parent page has any valid subpages:
// AbstractMenuContentObject.php
$cachePagesNextLevel = $this->sys_page->getMenu(
$pageIdsOnSameLevel,
'uid,pid,doktype,mount_pid,mount_pid_ol,nav_hide,shortcut,shortcut_mode,...', // no "link" field
'sorting',
'',
true, // checkShortcuts = true
$this->disableGroupAccessCheck
);
With `checkShortcuts = true`, `getMenu()` internally calls `checkValidLinkOfPage()` (introduced in 14.0) for every page of doktype=3. That method reads `$page[‘link’]`, but since `link` is not in the field list, it receives `null` and removes the page from the results:
// PageRepository::checkValidLinkOfPage()
$link = (string)($page['link'] ?? '');
if ($link === '') {
return []; // page removed — even if link field has data in the database
}
When the parent has only Link pages, `isSubMenu()` finds no valid children and caches `false`. This cached result is then used in `prepareMenuItems()` to skip the actual submenu query entirely, resulting in empty `children`.
When a regular page is present alongside Link pages, `isSubMenu()` finds it, caches `true`, and the submenu query runs with `*` fields — allowing Link pages to be correctly validated.
This is a regression (see: https://github.com/TYPO3/typo3/commit/784c72bf631650348ec2129eb2e16f3f46f9c8c8): before 14.0 there was no `checkValidLinkOfPage()`, so the restricted field list caused no issue.
There is also a structural concern: `isSubMenu()` uses a restricted field list as a performance optimisation, but `checkShortcuts = true` internally requires fields that are not in that list. Any future addition to shortcut/link validation logic will break this again. See also the existing `@todo` comment in `PageRepository::getMenu()` (line 840).
Fix
Fetch all fields in the batch query so that `checkShortcuts` validation has everything it needs. Strip the result down to only the fields consumed by the `foreach` loop before caching, to keep memory usage lean:
// Use * to ensure all fields required by checkShortcuts validation are available.
$fullPages = $this->sys_page->getMenu($pageIdsOnSameLevel, '*', 'sorting', '', true, $this->disableGroupAccessCheck);
// Cache only the fields actually used in the foreach loop below.
$cachePagesNextLevel = array_map(
static fn(array $page) => array_intersect_key(
$page,
array_flip(['uid', 'pid', 'doktype', 'nav_hide', 'l18n_cfg', '_LOCALIZED_UID']),
),
$fullPages,
);
This approach is future-proof: validation inside `getMenu()` always has all fields available, while the cached data remains minimal.
Affected file
`typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php` – method `isSubMenu()`