PageTreeFilter

FinalYes

Page tree filter implementation providing search functionality for the backend page tree.

This class implements page tree filtering through multiple event listeners that work together to provide comprehensive search capabilities including:

  • Numeric UID search (direct page ID lookup)
  • Wildcard text search in title/nav_title fields
  • Optional search in translated page titles
  • Visual labels indicating how pages were matched

Overview

The filtering process consists of two main phases:

  1. Query Building Phase (BeforePageTreeIsFilteredEvent)

    • addUidsFromSearchPhrase: Extracts numeric UIDs from search phrase
    • addWildCardAliasFilter: Adds LIKE queries for title/nav_title
    • addTranslatedPagesFilter: Queries translated pages (if enabled)
  2. Label Attachment Phase (AfterPageTreeItemsPreparedEvent)

    • attachSearchResultLabel: Adds "Search result" label to directly matched pages
    • attachTranslationInfoLabel: Adds translation info labels

Runtime Cache Usage

Translation matches are stored in runtime cache with the structure: [ pageUid => [languageUid1, languageUid2, ...] ]

This allows the label attachment phase to know which translations matched, enabling informative labels like "Found in translation: German".

The cache is populated during query building and consumed during label attachment. Cache key: 'pageTree_translationMatches'

User Configuration

Translation search can be controlled via:

  • TSConfig: options.pageTree.searchInTranslatedPages (default: true)
  • User Preference: pageTree_searchInTranslatedPages

Language restrictions from user groups are respected automatically.

Internal

Table of Contents

Methods

__construct()  : mixed
addTranslatedPagesFilter()  : void
Searches in translated page titles if translation search is enabled.
addUidsFromSearchPhrase()  : void
Extracts numeric page UIDs from the search phrase and adds them to the query.
addWildCardAliasFilter()  : void
Adds wildcard search conditions for title and nav_title fields.
attachSearchResultLabel()  : void
Attaches "Search result" labels to pages that directly matched the search.
attachTranslationInfoLabel()  : void
Attaches translation info labels to pages found via translated uid / content.

Methods

addTranslatedPagesFilter()

Searches in translated page titles if translation search is enabled.

public addTranslatedPagesFilter(BeforePageTreeIsFilteredEvent $event) : void

Performs a separate query to find translated pages (sys_language_uid > 0) whose title or nav_title matches the search phrase. When matches are found, the l10n_parent pages are added to search results with language information stored in runtime cache.

This allows finding pages like:

  • Default page "Products" with German translation "Produkte"
  • Searching for "Produkte" shows "Products" with label "Found in translation: German"

Respects:

  • User's language permissions (allowed_languages from user groups)
  • TSConfig setting options.pageTree.searchInTranslatedPages
  • User preference pageTree_searchInTranslatedPages
Parameters
$event : BeforePageTreeIsFilteredEvent
Attributes
#[AsEventListener]
'page-tree-translated-pages-filter'

addUidsFromSearchPhrase()

Extracts numeric page UIDs from the search phrase and adds them to the query.

public addUidsFromSearchPhrase(BeforePageTreeIsFilteredEvent $event) : void

When a user searches for "123", this method:

  1. Extracts the UID (123) and adds it to event->searchUids
  2. If translation search is enabled, checks if 123 is a translated page
  3. If yes, also adds the l10n_parent UID to show the default language page

Example: Searching for UID 456 where 456 is a German translation of page 123 will result in page 123 being shown with a "Found in translation: German" label.

Supports comma-separated UIDs: "123,456,789"

Parameters
$event : BeforePageTreeIsFilteredEvent
Attributes
#[AsEventListener]
'page-tree-uid-provider'

addWildCardAliasFilter()

Adds wildcard search conditions for title and nav_title fields.

public addWildCardAliasFilter(BeforePageTreeIsFilteredEvent $event) : void

Creates a LIKE query that searches in both the 'title' and 'nav_title' fields of default language pages.

Example: Searching for "Home" will find pages with:

  • title = "Homepage"
  • nav_title = "Home Navigation"
Parameters
$event : BeforePageTreeIsFilteredEvent
Attributes
#[AsEventListener]
'page-tree-wildcard-alias-filter'

attachSearchResultLabel()

Attaches "Search result" labels to pages that directly matched the search.

public attachSearchResultLabel(AfterPageTreeItemsPreparedEvent $event) : void

A page "directly matched" if its language is 0 and:

  • Its UID equals the numeric search phrase
  • Its title or nav_title contains the search phrase (case-insensitive)

Pages that matched via translations do NOT get this label - they get the translation info label instead.

Parameters
$event : AfterPageTreeItemsPreparedEvent
Attributes
#[AsEventListener]
'page-tree-add-search-result-label'

attachTranslationInfoLabel()

Attaches translation info labels to pages found via translated uid / content.

public attachTranslationInfoLabel(AfterPageTreeItemsPreparedEvent $event) : void

Reads translation match information from runtime cache (populated during the query building phase) and creates informative labels:

  • Single translation: "Found in translation: German"
  • Multiple translations: "Found in multiple translations"

The language name is resolved from the site configuration when possible.

Priority: 1 (shown before regular search result labels)

Parameters
$event : AfterPageTreeItemsPreparedEvent
Attributes
#[AsEventListener]
'page-tree-add-translation-status'

        
On this page

Search results