You are here

protected function DateBase::formatTextItem in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/DateBase.php \Drupal\webform\Plugin\WebformElement\DateBase::formatTextItem()

Format an element's value as text.

Parameters

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

array $options: An array of options.

Return value

string The element's value formatted as text.

Overrides WebformElementBase::formatTextItem

See also

_webform_token_get_submission_value()

File

src/Plugin/WebformElement/DateBase.php, line 189

Class

DateBase
Provides a base 'date' class.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatTextItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  $timestamp = strtotime($value);
  if (empty($timestamp)) {
    return $value;
  }
  $format = $this
    ->getItemFormat($element);
  if ($format === 'raw') {
    return $value;
  }
  elseif (DateFormat::load($format)) {
    return $this->dateFormatter
      ->format($timestamp, $format);
  }
  else {
    return static::formatDate($format, $timestamp);
  }
}