function ListElement::getGroupTitle

Same name in other branches
  1. 9 core/modules/config_translation/src/FormElement/ListElement.php \Drupal\config_translation\FormElement\ListElement::getGroupTitle()
  2. 8.9.x core/modules/config_translation/src/FormElement/ListElement.php \Drupal\config_translation\FormElement\ListElement::getGroupTitle()
  3. 10 core/modules/config_translation/src/FormElement/ListElement.php \Drupal\config_translation\FormElement\ListElement::getGroupTitle()

Returns the title for the 'details' element of a group of schema elements.

For some configuration elements the same element structure can be repeated multiple times (for example views displays, filters, etc.). Thus, we try to find a more usable title for the details summary. First check if there is an element which is called title or label and use its value. Then check if there is an element which contains these words and use those. Fall back to the generic definition label if no such element is found.

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface $definition: The definition of the schema element.

array $group_build: The renderable array for the group of schema elements.

Return value

string The title for the group of schema elements.

1 call to ListElement::getGroupTitle()
ListElement::getTranslationBuild in core/modules/config_translation/src/FormElement/ListElement.php
Builds a render array containing the source and translation form elements.

File

core/modules/config_translation/src/FormElement/ListElement.php, line 112

Class

ListElement
Defines the list element for the configuration translation interface.

Namespace

Drupal\config_translation\FormElement

Code

protected function getGroupTitle(DataDefinitionInterface $definition, array $group_build) {
    $title = '';
    if (isset($group_build['title']['source'])) {
        $title = $group_build['title']['source']['#markup'];
    }
    elseif (isset($group_build['label']['source'])) {
        $title = $group_build['label']['source']['#markup'];
    }
    else {
        foreach (array_keys($group_build) as $title_key) {
            if (isset($group_build[$title_key]['source']) && (str_contains($title_key, 'title') || str_contains($title_key, 'label'))) {
                $title = $group_build[$title_key]['source']['#markup'];
                break;
            }
        }
    }
    return (!empty($title) ? strip_tags($title) . ' ' : '') . $this->t($definition['label']);
}

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