protected function WebformElementBase::build in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElementBase.php \Drupal\webform\Plugin\WebformElementBase::build()
Build an element as text or HTML.
Parameters
string $format: Format of the element, text or html.
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $options: An array of options.
Return value
array A render array representing an element as text or HTML.
4 calls to WebformElementBase::build()
- Checkbox::build in src/
Plugin/ WebformElement/ Checkbox.php - Build an element as text or HTML.
- WebformElementBase::buildHtml in src/
Plugin/ WebformElementBase.php - Build an element as HTML element.
- WebformElementBase::buildText in src/
Plugin/ WebformElementBase.php - Build an element as text element.
- WebformOptionsCustom::build in modules/
webform_options_custom/ src/ Plugin/ WebformElement/ WebformOptionsCustom.php - Build an element as text or HTML.
4 methods override WebformElementBase::build()
- Checkbox::build in src/
Plugin/ WebformElement/ Checkbox.php - Build an element as text or HTML.
- ContainerBase::build in src/
Plugin/ WebformElement/ ContainerBase.php - Build an element as text or HTML.
- WebformOptionsCustom::build in modules/
webform_options_custom/ src/ Plugin/ WebformElement/ WebformOptionsCustom.php - Build an element as text or HTML.
- WebformTableRow::build in src/
Plugin/ WebformElement/ WebformTableRow.php - Build an element as text or HTML.
File
- src/
Plugin/ WebformElementBase.php, line 1342
Class
- WebformElementBase
- Provides a base class for a webform element.
Namespace
Drupal\webform\PluginCode
protected function build($format, array &$element, WebformSubmissionInterface $webform_submission, array $options = []) {
$options['multiline'] = $this
->isMultiline($element);
$format_function = 'format' . ucfirst($format);
$value = $this
->{$format_function}($element, $webform_submission, $options);
// Handle empty value or empty array.
if ($value === '' || is_array($value) && $value === []) {
// Return NULL if empty is excluded.
if ($this
->isEmptyExcluded($element, $options)) {
return NULL;
}
else {
$value = $this->configFactory
->get('webform.settings')
->get('element.empty_message');
}
}
// Convert string to renderable #markup.
if (is_string($value)) {
$value = [
'#' . ($format === 'text' ? 'plain_text' : 'markup') => $value,
];
}
return [
'#theme' => 'webform_element_base_' . $format,
'#element' => $element,
'#value' => $value,
'#webform_submission' => $webform_submission,
'#options' => $options,
];
}