You are here

public function WebformContentCreatorEntity::convertTimestamp in Webform Content Creator 8

Same name and namespace in other branches
  1. 3.x 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

int $datefield: Original datetime value.

array $fields: Content type fields.

int $fieldId: Field machine name id.

Return value

Timestamp Converted 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 633

Class

WebformContentCreatorEntity
Defines the Webform Content creator entity.

Namespace

Drupal\webform_content_creator\Entity

Code

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