You are here

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

Class

YamlFormCodeMirror
Provides a 'yamlform_codemirror' 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 'code':
      return [
        '#theme' => 'yamlform_codemirror',
        '#code' => $value,
        '#type' => $element['#mode'],
      ];
    default:
      return parent::formatHtml($element, $value, $options);
  }
}