You are here

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

Class

YamlFormTime
Provides a 'yamlform_time' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatText(array &$element, $value, array $options = []) {
  if (empty($value)) {
    return '';
  }
  $format = $this
    ->getFormat($element);
  if ($format == 'value') {
    $time_format = isset($element['#time_format']) ? $element['#time_format'] : 'H:i';
    return date($time_format, strtotime($value));
  }
  return parent::formatText($element, $value, $options);
}