public function WebformContentCreatorEntity::convertTimestamp in Webform Content Creator 2.x
Same name and namespace in other branches
- 8 src/Entity/WebformContentCreatorEntity.php \Drupal\webform_content_creator\Entity\WebformContentCreatorEntity::convertTimestamp()
- 3.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::mapContentField in src/
Entity/ WebformContentCreatorEntity.php - Use a single mapping to set a Content field value.
File
- src/
Entity/ WebformContentCreatorEntity.php, line 690
Class
- WebformContentCreatorEntity
- Defines the Webform Content Creator entity.
Namespace
Drupal\webform_content_creator\EntityCode
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;
}