mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Provide a TimestampItemNormalizer with an option to return RFC3339 formatted date.
This commit is contained in:
parent
6ccf2cda0d
commit
0a3a5084c1
2 changed files with 35 additions and 0 deletions
|
@ -13,3 +13,7 @@ services:
|
|||
tags:
|
||||
- { name: normalizer, priority: 10 }
|
||||
arguments: ['@entity.repository']
|
||||
farm_csv.normalizer.timestamp_item:
|
||||
class: Drupal\farm_csv\Normalizer\TimestampItemNormalizer
|
||||
tags:
|
||||
- { name: normalizer, priority: 10 }
|
||||
|
|
31
modules/core/csv/src/Normalizer/TimestampItemNormalizer.php
Normal file
31
modules/core/csv/src/Normalizer/TimestampItemNormalizer.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_csv\Normalizer;
|
||||
|
||||
use Drupal\serialization\Normalizer\TimestampItemNormalizer as CoreTimestampItemNormalizer;
|
||||
|
||||
/**
|
||||
* Normalizes timestamp fields for farmOS CSV exports.
|
||||
*/
|
||||
class TimestampItemNormalizer extends CoreTimestampItemNormalizer {
|
||||
|
||||
/**
|
||||
* The supported format.
|
||||
*/
|
||||
const FORMAT = 'csv';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function normalize($object, $format = NULL, array $context = []): array|string|int|float|bool|\ArrayObject|NULL {
|
||||
$data = parent::normalize($object, $format, $context);
|
||||
|
||||
// Return the RFC3339 formatted date, if desired.
|
||||
if (!empty($context['rfc3339_dates'])) {
|
||||
return $data['value'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue