protected static function WebformComputedBase::setWebformComputedElementValue in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformComputedBase.php \Drupal\webform\Element\WebformComputedBase::setWebformComputedElementValue()
Set computed element's value.
Parameters
array $element: A computed element.
string $value: A computer value.
2 calls to WebformComputedBase::setWebformComputedElementValue()
- WebformComputedBase::ajaxWebformComputedCallback in src/
Element/ WebformComputedBase.php - Webform computed element Ajax callback.
- WebformComputedBase::processWebformComputed in src/
Element/ WebformComputedBase.php - Processes a Webform computed token element.
File
- src/
Element/ WebformComputedBase.php, line 187
Class
- WebformComputedBase
- Provides a base class for 'webform_computed' elements.
Namespace
Drupal\webform\ElementCode
protected static function setWebformComputedElementValue(array &$element, $value) {
// Hide empty computed element using display:none so that #states API
// can still use the empty computed value.
if ($element['#hide_empty']) {
$element += [
'#wrapper_attributes' => [],
];
$element['#wrapper_attributes'] += [
'style' => '',
];
if ($value === '') {
$element['#wrapper_attributes']['style'] .= ($element['#wrapper_attributes']['style'] ? ';' : '') . 'display:none';
}
else {
$element['#wrapper_attributes']['style'] = preg_replace('/;?display:none/', '', $element['#wrapper_attributes']['style']);
}
}
// Display markup.
$element['value']['#markup'] = $value;
$element['value']['#allowed_tags'] = WebformXss::getAdminTagList();
// Include hidden element so that computed value will be available to
// conditions (#states).
$element['hidden']['#type'] = 'hidden';
$element['hidden']['#value'] = [
'#markup' => $value,
];
$element['hidden']['#parents'] = $element['#parents'];
}