public function Telephone::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/ Telephone.php, line 20
Class
- Telephone
- Provides a 'tel' 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':
// Issue #2484693: Telephone Link fied formatter breaks Drupal with 5
// digits or less in the number
// return [
// '#type' => 'link',
// '#title' => $value,
// '#url' => \Drupal::pathValidator()->getUrlIfValid('tel:' . $value),
// ];
// Workaround: Manually build a static HTML link.
$t_args = [
':tel' => 'tel:' . $value,
'@tel' => $value,
];
return t('<a href=":tel">@tel</a>', $t_args);
default:
return parent::formatHtml($element, $value, $options);
}
}