You are here

public function WebformContentCreatorEntity::convertTimestamp in Webform Content Creator 3.x

Same name and namespace in other branches
  1. 8 src/Entity/WebformContentCreatorEntity.php \Drupal\webform_content_creator\Entity\WebformContentCreatorEntity::convertTimestamp()
  2. 2.x src/Entity/WebformContentCreatorEntity.php \Drupal\webform_content_creator\Entity\WebformContentCreatorEntity::convertTimestamp()

Convert timestamp value according to field type.

Parameters

array $fields: Content type fields.

string $field_id: Field machine name.

string $value: Original datetime value.

Return value

string Converted datetime value.

1 call to WebformContentCreatorEntity::convertTimestamp()
WebformContentCreatorEntity::mapNodeField in src/Entity/WebformContentCreatorEntity.php
Use a single mapping to set a Node field value.

File

src/Entity/WebformContentCreatorEntity.php, line 655

Class

WebformContentCreatorEntity
Defines the Webform Content creator entity.

Namespace

Drupal\webform_content_creator\Entity

Code

public function convertTimestamp(array $fields, $field_id, $field_value) {
  $date_time = new DrupalDateTime($field_value, 'UTC');
  $date_type = $fields[$field_id]
    ->getSettings()['datetime_type'];
  if ($date_type === 'datetime') {
    $result = \Drupal::service('date.formatter')
      ->format($date_time
      ->getTimestamp(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT, 'UTC');
  }
  else {
    $result = \Drupal::service('date.formatter')
      ->format($date_time
      ->getTimestamp(), 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT, 'UTC');
  }
  return $result;
}