public function Url::formatHtml in YAML Form 8
Format an element's value as HTML.
Parameters
array $element: An element.
array|mixed $value: A value.
array $options: An array of options.
Return value
array|string The element's value formatted as an HTML string or a render array.
Overrides YamlFormElementBase::formatHtml
File
- src/
Plugin/ YamlFormElement/ Url.php, line 20
Class
- Url
- Provides a 'url' element.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function formatHtml(array &$element, $value, array $options = []) {
if (empty($value)) {
return '';
}
$format = $this
->getFormat($element);
switch ($format) {
case 'link':
return [
'#type' => 'link',
'#title' => $value,
'#url' => \Drupal::pathValidator()
->getUrlIfValid($value),
];
default:
return parent::formatHtml($element, $value, $options);
}
}