You are here

public function Email::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

1 call to Email::formatHtml()
YamlFormEmailMultiple::formatHtml in src/Plugin/YamlFormElement/YamlFormEmailMultiple.php
Format an element's value as HTML.
1 method overrides Email::formatHtml()
YamlFormEmailMultiple::formatHtml in src/Plugin/YamlFormElement/YamlFormEmailMultiple.php
Format an element's value as HTML.

File

src/Plugin/YamlFormElement/Email.php, line 34

Class

Email
Provides a 'email' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

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('mailto:' . $value),
      ];
    default:
      return parent::formatHtml($element, $value, $options);
  }
}