Guides

ToctreeSortingTransformer
in package
implements NodeTransformer

FinalYes

Table of Contents

Interfaces

NodeTransformer

Methods

enterNode()  : T
getPriority()  : int
The higher the priority the earlier the NodeTransformer is executed.
leaveNode()  : T|null
supports()  : bool
collectTocNodes()  : array<string|int, TocNode>
Collects the toctrees of a document in document order.
menuEntryKey()  : string
sortMenuEntriesByToctrees()  : array<string|int, DocumentEntryNode|ExternalEntryNode>|null
Reorders the menu entries of a document so they follow the order authored in its toctrees.

Methods

getPriority()

The higher the priority the earlier the NodeTransformer is executed.

public getPriority() : int
Return values
int

collectTocNodes()

Collects the toctrees of a document in document order.

private static collectTocNodes(Node $node) : array<string|int, TocNode>

DocumentNode::getTocNodes() is filled by TocNodeTransformer at priority 1000, which runs after this pass, and getNodes() only looks at direct children while a toctree usually sits inside a section. So the tree is walked here.

Parameters
$node : Node
Return values
array<string|int, TocNode>

sortMenuEntriesByToctrees()

Reorders the menu entries of a document so they follow the order authored in its toctrees.

private sortMenuEntriesByToctrees(DocumentNode $documentNode, array<string|int, DocumentEntryNode|ExternalEntryNode$menuEntries) : array<string|int, DocumentEntryNode|ExternalEntryNode>|null

The order is taken from all toctrees of the document at once, in document order, rather than from the toctree currently visited: the menu entries the sorting starts from are grouped by type, so a single toctree cannot tell where its own block belongs relative to the others. Running this for every toctree of the document is idempotent, and the last run sees every :reversed: toctree already reversed.

Nothing is reordered when a menu entry is attached that no toctree of the document accounts for: reordering only part of the list would be worse than not reordering it. Null is returned in that case.

Parameters
$documentNode : DocumentNode
$menuEntries : array<string|int, DocumentEntryNode|ExternalEntryNode>
Return values
array<string|int, DocumentEntryNode|ExternalEntryNode>|null
On this page

Search results