public Textfield::getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config)
Returns the translation form element for a given configuration definition.
For complex data structures (such as mappings) that are translatable wholesale but contain non-translatable properties, the form element is responsible for checking access to the source value of those properties. In case of formatted text, for example, access to the source text format must be checked. If the translator does not have access to the text format, the textarea must be disabled and the translator may not be able to translate this particular configuration element. If the translator does have access to the text format, the element must be locked down to that particular text format; in other words, the format may not be changed by the translator (because the text format property is not itself translatable).
In addition, the form element is responsible for checking whether the value of such non-translatable properties in the translated configuration is equal to the corresponding source values. If not, that means that the source value has changed after the translation was added. In this case - again - the translation of this element must be disabled if the translator does not have access to the source value of the non-translatable property. For example, if a formatted text element, whose source format was plain text when it was first translated, gets changed to the Full HTML format, simply changing the format of the translation would lead to an XSS vulnerability as the translated text, that was intended to be escaped, would now be displayed unescaped. Thus, if the translator does not have access to the Full HTML format, the translation for this particular element may not be updated at all (the textarea must be disabled). Only if access to the Full HTML format is granted, an explicit translation taking into account the updated source value(s) may be submitted.
In the specific case of formatted text this logic is implemented by utilizing a form element of type 'text_format' and its #format and #allowed_formats properties. The access logic explained above is then handled by the 'text_format' element itself, specifically by filter_process_format(). In case such a rich element is not available for translation of complex data, similar access logic must be implemented manually.
Parameters
\Drupal\Core\Language\LanguageInterface $translation_language: The language to display the translation form for.
mixed $source_config: The configuration value of the element in the source language.
mixed $translation_config: The configuration value of the element in the language to translate to.
Return value
array Form API array to represent the form element.
Overrides FormElementBase::getTranslationElement
See also
\Drupal\config_translation\FormElement\TextFormat
filter_process_format()
File
- core/modules/config_translation/src/FormElement/Textfield.php, line 15
Class
- Textfield
- Defines the textfield element for the configuration translation interface.
Namespace
Drupal\config_translation\FormElement
Code
public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) { return array( '#type' => 'textfield', ) + parent::getTranslationElement($translation_language, $source_config, $translation_config); }
Please login to continue.