protected function YamlFormElementBase::build in YAML Form 8
Build an element as text or HTML.
Parameters
string $format: Format of the element, text or html.
array $element: An element.
array|mixed $value: A value.
array $options: An array of options.
Return value
array A render array representing an element as text or HTML.
3 calls to YamlFormElementBase::build()
- Table::build in src/
Plugin/ YamlFormElement/ Table.php - Build an element as text or HTML.
- YamlFormElementBase::buildHtml in src/
YamlFormElementBase.php - Build an element as HTML element.
- YamlFormElementBase::buildText in src/
YamlFormElementBase.php - Build an element as text element.
2 methods override YamlFormElementBase::build()
- ContainerBase::build in src/
Plugin/ YamlFormElement/ ContainerBase.php - Build an element as text or HTML.
- Table::build in src/
Plugin/ YamlFormElement/ Table.php - Build an element as text or HTML.
File
- src/
YamlFormElementBase.php, line 586
Class
- YamlFormElementBase
- Provides a base class for a form element.
Namespace
Drupal\yamlformCode
protected function build($format, array &$element, $value, array $options = []) {
$options['multiline'] = $this
->isMultiline($element);
$format_function = 'format' . ucfirst($format);
$formatted_value = $this
->{$format_function}($element, $value, $options);
// Return NULL for empty formatted value.
if ($formatted_value === '') {
return NULL;
}
// Convert string to renderable #markup.
if (is_string($formatted_value)) {
$formatted_value = [
'#markup' => $formatted_value,
];
}
return [
'#theme' => 'yamlform_element_base_' . $format,
'#element' => $element,
'#value' => $formatted_value,
'#options' => $options,
];
}