You are here

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

Class

OptionsBase
Provides a base 'options' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatHtml(array &$element, $value, array $options = []) {
  if ($value && is_array($value) && ($list_type = $this
    ->getListType($element))) {
    $flattened_options = OptGroup::flattenOptions($element['#options']);
    return [
      '#theme' => 'item_list',
      '#items' => YamlFormOptionsHelper::getOptionsText($value, $flattened_options),
      '#list_type' => $list_type,
    ];
  }
  else {
    return parent::formatHtml($element, $value, $options);
  }
}