Untitled
unknown
plain_text
6 months ago
834 B
4
Indexable
function mymodule_node_presave(\Drupal\Core\Entity\EntityInterface $entity) { if ($entity->bundle() == 'your_content_type' && !$entity->isNew()) { // Check and set the start date. if (!empty($entity->get('field_date')->value)) { $start_date = new \DateTime($entity->get('field_date')->value, new \DateTimeZone('Europe/Zurich')); $start_date->setTimezone(new \DateTimeZone('UTC')); $entity->set('field_date', $start_date->format('Y-m-d\TH:i:s')); } // Check and set the end date. if (!empty($entity->get('field_date')->end_value)) { $end_date = new \DateTime($entity->get('field_date')->end_value, new \DateTimeZone('Europe/Zurich')); $end_date->setTimezone(new \DateTimeZone('UTC')); $entity->set('field_date', ['end_value' => $end_date->format('Y-m-d\TH:i:s')]); } } }
Editor is loading...
Leave a Comment