public function DateTimeFromStringEnhancer::prepareForInput in JSON:API Extras 8
Apply the initial transformations to the input value of a single field.
Parameters
mixed $value: The value to be processed so it can be used as an input.
Return value
mixed The value after being post precessed.
Overrides DateTimeEnhancerBase::prepareForInput
File
- src/
Plugin/ jsonapi/ FieldEnhancer/ DateTimeFromStringEnhancer.php, line 36
Class
- DateTimeFromStringEnhancer
- Perform additional manipulations to datetime fields.
Namespace
Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancerCode
public function prepareForInput($value) {
$date = new \DateTime($value);
// Adjust the date for storage.
$storage_timezone = new \DateTimezone(DATETIME_STORAGE_TIMEZONE);
$date
->setTimezone($storage_timezone);
return $date
->format(DATETIME_DATETIME_STORAGE_FORMAT);
}