Skip to content

[BUGFIX] Keep navigation menu in toctree order with external links#1291

Open
CybotTM wants to merge 1 commit into
TYPO3-Documentation:mainfrom
CybotTM:fix/issue-1175-menu-toctree-order
Open

[BUGFIX] Keep navigation menu in toctree order with external links#1291
CybotTM wants to merge 1 commit into
TYPO3-Documentation:mainfrom
CybotTM:fix/issue-1175-menu-toctree-order

Conversation

@CybotTM

@CybotTM CybotTM commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #1175

Problem

When a toctree mixes internal pages and external links (e.g. interlinks to other manuals), the sidebar navigation renders all external entries grouped at the top, even though the on-page toctree keeps the authored order. On the reported page (reference-coreapi → Fluid) the sidebar shows Fluid Syntax and ViewHelper reference (both external) above the internal pages.

Root cause

The guides compiler attaches a document's menu entries via separate transformers for internal and external entries (InternalMenuEntryNodeTransformer / ExternalMenuEntryNodeTransformer), and the compiler runs one full tree traversal per transformer at each priority. So every external entry is attached to the document's menu-entry list in one pass and every internal entry in another — the list ends up grouped by type instead of following the authored toctree. The on-page toctree renders from the TocNode (authored order) and stays correct; the sidebar renders from DocumentEntryNode::getMenuEntries() and does not.

This is an engine-level issue in phpdocumentor/guides. The proper fix belongs upstream (phpDocumentor/guides#1344); this PR adds a downstream compiler pass so docs.typo3.org is fixed now, and it can be removed after a future guides bump.

Fix

SortMenuEntriesByToctreeTransformer realigns each document's menu entries with the authored order of its toctrees, matching entries by file/URL. It emits each toctree's entries as one contiguous block at the position of its first entry, so a document with several mixed toctrees is ordered correctly too. Globbed toctrees are skipped (their order comes from the glob expansion, which the sitemap relies on).

Before / after

Sidebar of a subpage whose toctree mixes internal pages with two external links:

Before

before

After

after

Verification

  • Two integration fixtures: tests-full/menu-external-order (one nested mixed toctree) and tests-full/menu-multiple-toctrees-order (two mixed toctrees on one page). Each passes with the fix and fails without it.
  • Full integration suite green (116 tests); the change touches only mixed/explicit toctrees — external-menu, two-toctrees, menu-subpages, sitemap (glob) and main-menu-json are unaffected.
  • PHPStan (repo config) and php-cs-fixer clean on the changed files.

@CybotTM CybotTM force-pushed the fix/issue-1175-menu-toctree-order branch 2 times, most recently from 80a6384 to 64824a6 Compare June 19, 2026 15:48
@CybotTM

CybotTM commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

looking into failing CI ...

@CybotTM CybotTM force-pushed the fix/issue-1175-menu-toctree-order branch 3 times, most recently from a025887 to 9a35cc8 Compare June 24, 2026 15:31
A toctree that mixes internal pages and external links rendered the
navigation menu (sidebar) with all external links grouped at the top,
while the on-page toctree kept the authored order.

The guides compiler attaches a document's menu entries via separate
transformers for internal and external entries, each running in its own
full tree traversal, so the document entry's menu entries end up grouped
by type instead of following the toctree. The sidebar, built from those
menu entries, then disagreed with the page.

Add a compiler pass that realigns the menu entries of each (non-glob)
toctree with the authored order, emitting each toctree's entries as a
contiguous block at the position of its first entry so a document with
several mixed toctrees is also handled. This is a downstream workaround
that can be dropped once the fix lands upstream in phpdocumentor/guides.

Resolves: TYPO3-Documentation#1175
Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
@CybotTM CybotTM force-pushed the fix/issue-1175-menu-toctree-order branch from 9a35cc8 to b253a66 Compare July 1, 2026 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Different sorting in menu than in toctree

1 participant