You are here

protected function DateBase::parseInputFormat in Webform 6.x

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

Parse GNU Date Input Format.

Parameters

array $element: An element.

string $property: The element's date property.

1 call to DateBase::parseInputFormat()
DateBase::prepare in src/Plugin/WebformElement/DateBase.php
Prepare an element to be rendered within a webform.

File

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

Class

DateBase
Provides a base 'date' class.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function parseInputFormat(array &$element, $property) {
  if (!isset($element[$property])) {
    return;
  }
  elseif (is_array($element[$property])) {
    foreach ($element[$property] as $key => $value) {
      $timestamp = strtotime($value);
      $element[$property][$key] = $timestamp ? $this->dateFormatter
        ->format($timestamp, 'html_' . $this
        ->getDateType($element)) : NULL;
    }
  }
  else {
    $timestamp = strtotime($element[$property]);
    $element[$property] = $timestamp ? $this->dateFormatter
      ->format($timestamp, 'html_' . $this
      ->getDateType($element)) : NULL;
  }
}