function ContentTranslationHandler::addTranslatabilityClue

Same name in other branches
  1. 9 core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::addTranslatabilityClue()
  2. 8.9.x core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::addTranslatabilityClue()
  3. 11.x core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::addTranslatabilityClue()

Adds a clue about the form element translatability.

If the given element does not have a #title attribute, the function is recursively applied to child elements.

Parameters

array $element: A form element array.

1 call to ContentTranslationHandler::addTranslatabilityClue()
ContentTranslationHandler::entityFormSharedElements in core/modules/content_translation/src/ContentTranslationHandler.php
Process callback: determines which elements get clue in the form.

File

core/modules/content_translation/src/ContentTranslationHandler.php, line 677

Class

ContentTranslationHandler
Base class for content translation handlers.

Namespace

Drupal\content_translation

Code

protected function addTranslatabilityClue(&$element) {
    static $suffix, $fapi_title_elements;
    // Elements which can have a #title attribute according to FAPI Reference.
    if (!isset($suffix)) {
        $suffix = ' <span class="translation-entity-all-languages">(' . t('all languages') . ')</span>';
        $fapi_title_elements = array_flip([
            'checkbox',
            'checkboxes',
            'date',
            'details',
            'fieldset',
            'file',
            'item',
            'password',
            'password_confirm',
            'radio',
            'radios',
            'select',
            'text_format',
            'textarea',
            'textfield',
            'weight',
        ]);
    }
    // Update #title attribute for all elements that are allowed to have a
    // #title attribute according to the Form API Reference. The reason for this
    // check is because some elements have a #title attribute even though it is
    // not rendered; for instance, field containers.
    if (isset($element['#type']) && isset($fapi_title_elements[$element['#type']]) && isset($element['#title'])) {
        $element['#title'] .= $suffix;
    }
    elseif ($children = Element::children($element)) {
        foreach ($children as $delta) {
            $this->addTranslatabilityClue($element[$delta]);
        }
    }
    elseif (isset($element['#title'])) {
        $element['#title'] .= $suffix;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.