Make MetaModels items findable through Contao's back end search - #1596
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dataContaineris exactlyContao\DC_Table(TableDataContainerProvider). Every MetaModels table uses dc-general'sGeneral::classinstead, so nothing ever showed up in a search.ItemProvider, acontao.backend_search_providerfor MetaModels item tables, built through MetaModels' own APIs:IFactoryfor item data (honouring the existingsearchableflag ontl_metamodel_dcasetting),ViewCombinationfor permissions and the title (tl_metamodel_dca_combine, since MetaModels does not register in$GLOBALS['BE_MOD']), and themetamodels.metamodelroute for the edit link (same shape theFileUsageProviders already use).ITranslated::getTranslatedDataFor(), the same checkFallbackLanguageHintListeneruses for the "Fallback" badge) rather than one hit merged across languages or duplicated for languages that only fall back to the main one.ratingattribute'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
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)phpcq runclean (psalm, phpmd) onmetamodels/core