DateTime.php in Feeds 8.3
File
src/Feeds/Target/DateTime.php
View source
<?php
namespace Drupal\feeds\Feeds\Target;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
class DateTime extends DateTargetBase {
protected $storageFormat;
public function __construct(array $configuration, $plugin_id, array $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->storageFormat = $this->settings['datetime_type'] === 'date' ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
}
protected function prepareValue($delta, array &$values) {
$values['value'] = $this
->prepareDateValue($values['value']);
}
protected function prepareDateValue($value) {
$date = $this
->convertToDate($value);
if (isset($date) && !$date
->hasErrors()) {
return $date
->format($this->storageFormat, [
'timezone' => DateTimeItemInterface::STORAGE_TIMEZONE,
]);
}
return '';
}
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'timezone' => DateTimeItemInterface::STORAGE_TIMEZONE,
];
}
}