function DateElementBase::getElementTitle

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Datetime/Element/DateElementBase.php \Drupal\Core\Datetime\Element\DateElementBase::getElementTitle()
  2. 10 core/lib/Drupal/Core/Datetime/Element/DateElementBase.php \Drupal\Core\Datetime\Element\DateElementBase::getElementTitle()
  3. 11.x core/lib/Drupal/Core/Datetime/Element/DateElementBase.php \Drupal\Core\Datetime\Element\DateElementBase::getElementTitle()

Returns the most relevant title of a datetime element.

Since datetime form elements often consist of combined date and time fields the element title might not be located on the element itself but on the parent container element.

Parameters

array $element: The element being processed.

array $complete_form: The complete form structure.

Return value

string The title.

1 call to DateElementBase::getElementTitle()
Datelist::validateDatelist in core/lib/Drupal/Core/Datetime/Element/Datelist.php
Validation callback for a datelist element.

File

core/lib/Drupal/Core/Datetime/Element/DateElementBase.php, line 88

Class

DateElementBase
Provides a base class for date elements.

Namespace

Drupal\Core\Datetime\Element

Code

protected static function getElementTitle($element, $complete_form) {
    $title = '';
    if (!empty($element['#title'])) {
        $title = $element['#title'];
    }
    else {
        $parents = $element['#array_parents'];
        array_pop($parents);
        $parent_element = NestedArray::getValue($complete_form, $parents);
        if (!empty($parent_element['#title'])) {
            $title = $parent_element['#title'];
        }
    }
    return $title;
}

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