You are here

public function DateBase::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

1 call to DateBase::formatText()
DateBase::buildExportRecord in src/Plugin/YamlFormElement/DateBase.php
Build an element's export row.

File

src/Plugin/YamlFormElement/DateBase.php, line 67

Class

DateBase
Provides a base 'date' class.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatText(array &$element, $value, array $options = []) {
  $timestamp = strtotime($value);
  if (empty($timestamp)) {
    return $value;
  }
  $format = $this
    ->getFormat($element) ?: 'html_' . $this
    ->getDateType($element);
  if (DateFormat::load($format)) {
    return \Drupal::service('date.formatter')
      ->format($timestamp, $format);
  }
  else {
    return date($format, $timestamp);
  }
}