You are here

public function YamlFormManagedFileBase::formatText in YAML Form 8

Format an element's value as plain text.

Parameters

array $element: An element.

array|mixed $value: A value.

array $options: An array of options.

Return value

string The element's value formatted as plain text or a render array.

Overrides YamlFormElementBase::formatText

File

src/Plugin/YamlFormElement/YamlFormManagedFileBase.php, line 187

Class

YamlFormManagedFileBase
Provides a base class form 'managed_file' elements.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatText(array &$element, $value, array $options = []) {
  if (empty($value)) {
    return '';
  }
  if (empty($element['#format']) || $element['#format'] == 'link') {
    $element['#format'] = 'url';
  }
  $items = $this
    ->formatItems($element, $value, $options);
  if (empty($items)) {
    return '';
  }

  // Add dash (aka bullet) before each item.
  if ($this
    ->hasMultipleValues($element)) {
    foreach ($items as &$item) {
      $item = '- ' . $item;
    }
  }
  return implode("\n", $items);
}