Skip to content

Make MetaModels items findable through Contao's back end search - #1596

Merged
zonky2 merged 1 commit into
release/2.5from
feature/backend-search-item-provider
Sep 4, 2026
Merged

Make MetaModels items findable through Contao's back end search#1596
zonky2 merged 1 commit into
release/2.5from
feature/backend-search-item-provider

Conversation

@zonky2

@zonky2 zonky2 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Contao 5.5's back end search only indexes tables whose dataContainer is exactly Contao\DC_Table (TableDataContainerProvider). Every MetaModels table uses dc-general's General::class instead, so nothing ever showed up in a search.
  • Add ItemProvider, a contao.backend_search_provider for MetaModels item tables, built through MetaModels' own APIs: IFactory for item data (honouring the existing searchable flag on tl_metamodel_dcasetting), ViewCombination for permissions and the title (tl_metamodel_dca_combine, since MetaModels does not register in $GLOBALS['BE_MOD']), and the metamodels.metamodel route for the edit link (same shape the FileUsageProviders already use).
  • Translated MetaModels get one hit per language that actually has its own value (ITranslated::getTranslatedDataFor(), the same check FallbackLanguageHintListener uses for the "Fallback" badge) rather than one hit merged across languages or duplicated for languages that only fall back to the main one.
  • Attribute rendering that throws (e.g. a rating attribute's template assuming an HTTP request, which the CLI/messenger reindex worker doesn't have) is caught per item so it can't sink the whole reindex job.

Test plan

  • Verified against the devstack (mm_employees, mm_employees_trans): search finds item content, edit link opens the correct item (and, for translated items, the correct language tab via &language=xx)
  • Confirmed a language without any own translation for the item does not produce a duplicate hit
  • phpcq run clean (psalm, phpmd) on metamodels/core

Contao 5.5's new back end search only indexes tables whose "dataContainer"
is exactly Contao\DC_Table (TableDataContainerProvider). Every MetaModels
table uses dc-general's General::class instead, so none of it - neither
the tl_metamodel_* configuration tables nor any item table - ever showed
up in a search, no matter which fields were marked searchable.

Add ItemProvider, a "contao.backend_search_provider" for MetaModels item
tables, built through MetaModels' own APIs rather than Contao's DC_Table
assumptions:
- IFactory for the item data, using the existing "searchable" flag on
  tl_metamodel_dcasetting (the same one the frontend search already
  honours) to pick which attributes contribute text.
- ViewCombination for both the permission check and the title (via
  tl_metamodel_dca_combine, since MetaModels deliberately does not
  register in $GLOBALS['BE_MOD'] and therefore has no per-table alexf
  right to fall back to).
- The "metamodels.metamodel" route for the edit link, the same URL shape
  the FileUsageProviders already build.

Translated MetaModels get one hit per language rather than one merged
hit per item, mirroring how the translated-attribute FileUsageProviders
build one result per language. A language only gets its own hit when an
item actually has a value of its own in that language
(ITranslated::getTranslatedDataFor(), the same check
FallbackLanguageHintListener uses for the "Fallback" badge in the edit
view) - otherwise MetaModels silently renders the main language's value
instead, which would just duplicate the main-language hit under every
untranslated language.

Attribute rendering can throw for types whose template assumes an HTTP
request is available (e.g. building absolute image URLs for a "rating"
attribute), which does not hold on the CLI/messenger worker a reindex
runs on - caught per item so one such attribute cannot sink the whole
job.
@zonky2
zonky2 merged commit 0f77749 into release/2.5 Sep 4, 2026
4 checks passed
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.

1 participant