You are here

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

Class

YamlFormManagedFileBase
Provides a base class form 'managed_file' elements.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatHtml(array &$element, $value, array $options = []) {
  if (empty($value)) {
    return '';
  }
  $items = $this
    ->formatItems($element, $value, $options);
  if (empty($items)) {
    return '';
  }
  if ($this
    ->hasMultipleValues($element)) {
    return [
      '#theme' => 'item_list',
      '#items' => $items,
    ];
  }
  else {
    return reset($items);
  }
}