FormElementHelper::getElementTitle

public static FormElementHelper::getElementTitle(array $element)

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.

File

core/lib/Drupal/Core/Form/FormElementHelper.php, line 48

Class

FormElementHelper
Provides common functionality for form elements.

Namespace

Drupal\Core\Form

Code

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;
}
doc_Drupal
2016-10-29 09:15:38
Comments
Leave a Comment

Please login to continue.