You are here

protected static function WebformTableTrait::buildElementTitle in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/WebformTableTrait.php \Drupal\webform\Plugin\WebformElement\WebformTableTrait::buildElementTitle()

Build an element's title with help.

Parameters

array $element: An element.

Return value

array A render array containing an element's title with help.

1 call to WebformTableTrait::buildElementTitle()
WebformTableTrait::prepare in src/Plugin/WebformElement/WebformTableTrait.php

File

src/Plugin/WebformElement/WebformTableTrait.php, line 248

Class

WebformTableTrait
Provides a 'table' trait.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected static function buildElementTitle(array $element) {
  $title = !empty($element['#title']) ? $element['#title'] : '';
  $help = !empty($element['#help']) ? [
    '#type' => 'webform_help',
    '#help' => $element['#help'],
    '#help_title' => $title,
  ] : NULL;
  $help_display = !empty($element['#help_display']) ? $element['#help_display'] : 'title_after';
  $build = [];
  if ($help && $help_display === 'title_before') {
    $build['help'] = $help;
  }
  $build['title'] = [
    '#markup' => $title,
  ];
  if (!empty($element['#required']) || !empty($element['#_required'])) {
    $build['title'] += [
      '#prefix' => '<span class="form-required">',
      '#suffix' => '</span>',
    ];
  }
  if ($help && $help_display === 'title_after') {
    $build['help'] = $help;
  }
  return $build;
}