public function WebformTableTrait::prepare in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElement/WebformTableTrait.php \Drupal\webform\Plugin\WebformElement\WebformTableTrait::prepare()
File
- src/Plugin/WebformElement/WebformTableTrait.php, line 18
Class
- WebformTableTrait
- Provides a 'table' trait.
Namespace
Drupal\webform\Plugin\WebformElement
Code
public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
parent::prepare($element, $webform_submission);
$element['#attributes']['class'][] = str_replace('_', '-', $element['#type']);
if (!isset($element['#header'])) {
if (empty($element['#title_display']) || $element['#title_display'] === 'header') {
$element['#header'] = [
[
'data' => static::buildElementTitle($element),
],
];
}
else {
$element['#header'] = [
'',
];
}
}
if (empty($element['#title_display']) || $element['#title_display'] === 'header') {
$element['#title_display'] = 'none';
}
if (isset($element['#options'])) {
foreach ($element['#options'] as $options_key => $options_value) {
if (is_string($options_value)) {
$element['#options'][$options_key] = [
[
'value' => $options_value,
],
];
}
}
}
$element['#attached']['library'][] = 'webform/webform.element.' . $element['#type'];
if ($this
->getPluginId() === 'tableselect') {
static::setProcessTableSelectCallback($element);
}
$element['#theme_wrappers'][] = 'form_element';
$element['#label_attributes']['webform-remove-for-attribute'] = TRUE;
}