You are here

public function YamlFormSignature::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/YamlFormSignature.php, line 44

Class

YamlFormSignature
Provides a 'signature' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatHtml(array &$element, $value, array $options = []) {
  $format = $this
    ->getFormat($element);
  switch ($format) {
    case 'image':
      if (empty($value)) {
        return '[' . $this
          ->t('not signed') . ']';
      }

      // Most email clients do not support data uri.
      // @see http://stackoverflow.com/questions/6070196/what-is-data-uri-support-like-in-major-email-client-software
      if (!empty($options['email'])) {
        return '[' . $this
          ->t('singed') . ']';
      }
      return [
        '#type' => 'html_tag',
        '#tag' => 'img',
        '#attributes' => [
          'src' => $value,
          'alt' => $this
            ->t('Signature'),
          'class' => [
            'yamlform-signature-pad-image',
          ],
        ],
        '#attached' => [
          'library' => [
            'yamlform/yamlform.element.signature',
          ],
        ],
      ];
    default:
      return parent::formatHtml($element, $value, $options);
  }
}