You are here

public static function DateBase::afterBuild in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/DateBase.php \Drupal\webform\Plugin\WebformElement\DateBase::afterBuild()

After build handler for date elements.

1 call to DateBase::afterBuild()
DateList::afterBuild in src/Plugin/WebformElement/DateList.php
After build handler for Datelist element.
1 method overrides DateBase::afterBuild()
DateList::afterBuild in src/Plugin/WebformElement/DateList.php
After build handler for Datelist element.

File

src/Plugin/WebformElement/DateBase.php, line 160

Class

DateBase
Provides a base 'date' class.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public static function afterBuild(array $element, FormStateInterface $form_state) {

  // Add parent title to sub-elements to child elements which applies to
  // datetime and datelist elements.
  $child_keys = Element::children($element);
  foreach ($child_keys as $child_key) {
    if (isset($element[$child_key]['#title'])) {
      $t_args = [
        '@parent' => $element['#title'],
        '@child' => $element[$child_key]['#title'],
      ];
      $element[$child_key]['#title'] = t('@parent: @child', $t_args);
    }
  }

  // Remove orphaned form label.
  if ($child_keys) {
    $element['#label_attributes']['webform-remove-for-attribute'] = TRUE;
  }
  return $element;
}