Problem/Motivation
ConfigMapperManager::findTranslatable() ignores the translatable flag on mappings and sequences. Without a translatable leaf, the overview and translation form return HTTP 403. Adding some unrelated label value, however, makes the existing widget accessible.
A mapping or sequence can legitimately vary by language even when none of its individual values should be offered for interface translation.
- A clinic in Quebec links to after-hours care instructions on page 3 of its French patient guide and page 5 of its English guide. The editor selects guide and page together because the page number depends on the edition.
- A staff directory may display "Anna Kovács" in English and "Kovács Anna" in Hungarian. A widget lets the editor reorder
given_nameandfamily_nameper language. The field names themselves, however, are language-independent and need no translation. - A site may send page views from its English and German sections to different analytics accounts. An account picker lets an editor choose the account for each language.
Background
Before #2097101: Remove deprecated functions , marking only the configuration object as translatable did not grant access to the translation form. The check started with its children. A mapping nested inside it, however, could grant access through its own translatable flag even when none of its values was translatable.
Comment #24 changed the check so it could also handle a single, standalone value. In the process, mappings and sequences came to count only if they contained a translatable leaf. Supporting standalone values does not require this restriction: a mapping can have its own translation widget precisely because its values need to be edited together.
#1952394: Add configuration translation user interface module in core brought that behavior into Core.
@tstoeckler proposed supporting the analytics use case in #2275865-1: Per language settings (vs translated settings) are not directly supported, and later confirmed it in comment #10 after #2144413: Config translation does not support text elements with a format had landed.
Steps to reproduce
In #3240618: Allow CX code to be translatable., Simple Google Custom Search Engine added support for choosing a different search engine per language.
The released module marks its settings object as translatable and declares the search engine ID (cx) as text. To reproduce the bug, keep the settings object translatable and mark only cx as non-translatable.
- On an English Drupal 11 site, enable Configuration Translation and Simple Google Custom Search Engine 2.0.2, and add French. As an administrator, enter
example-enat/admin/config/search/simple_gse_searchand save. No Google account is needed. - Open
/admin/config/search/simple_gse_search/translateand choose "Add" for French. The released module shows a textarea for the ID. Leave the form without saving. - In the module's
config/schema/simple_gse_search.schema.yml, keeptranslatable: trueonsimple_gse_search.settings. However, addtranslatable: falseto thecxfield:
cx: label: 'Google Search ID' type: text translatable: falseThis makes more sense, because although each language can use a different search engine, each engine’s
cxis a fixed ID that needs no translation. - Rebuild caches.
- Revisit the translation overview. It now returns HTTP 403. Opening the French form directly at
/admin/config/search/simple_gse_search/translate/fr/addalso returns HTTP 403.
With the proposed fix, both pages open. Entering example-fr in the French form and saving sets the French search engine ID to example-fr. The base configuration retains example-en.
Proposed resolution
Check the translatable flag on each mapping or sequence before searching its children. If the flag is the boolean TRUE, return TRUE. Otherwise, continue searching the children. Preserve the existing flag handling for leaves.
Remaining tasks
Review whether the translation form should be accessible when a marked container uses the default list widget and none of its children provides an editable field.
User interface changes
Translators can open the translation overview and form when the only translatable element is a mapping or sequence.
Introduced terminology
None.
API changes
ConfigMapperManager::hasTranslatable() now counts mappings and sequences marked translatable: true, even when they contain no translatable leaves.
Data model changes
None.
Release notes snippet
Translators can now use a module’s widget to translate a group of settings as a whole, even when none of its individual values is marked translatable.
Issue fork drupal-3644437
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
panchoComment #4
pancho