public static function FormElementHelper::getElementTitle in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Form/FormElementHelper.php \Drupal\Core\Form\FormElementHelper::getElementTitle()
Returns the title for the element.
If the element has no title, this will recurse through all children of the element until a title is found.
Parameters
array $element: An associative array containing the properties of the form element.
Return value
string The title of the element, or an empty string if none is found.
2 calls to FormElementHelper::getElementTitle()
- FormElementHelperTest::testGetElementTitle in core/
tests/ Drupal/ Tests/ Core/ Form/ FormElementHelperTest.php - Tests the getElementTitle() method.
- FormErrorHandler::displayErrorMessages in core/
modules/ inline_form_errors/ src/ FormErrorHandler.php - Loops through and displays all form errors.
File
- core/
lib/ Drupal/ Core/ Form/ FormElementHelper.php, line 48
Class
- FormElementHelper
- Provides common functionality for form elements.
Namespace
Drupal\Core\FormCode
public static function getElementTitle(array $element) {
$title = '';
if (isset($element['#title'])) {
$title = $element['#title'];
}
else {
foreach (Element::children($element) as $key) {
if ($title = static::getElementTitle($element[$key])) {
break;
}
}
}
return $title;
}