Example how to set date field programmatically drupal 8 / 9
function mymodule_entity_presave(EntityInterface $entity) { if ($entity->getEntityTypeId() == 'node') { $dateTime = DateTime::createFromFormat('Y-m-d',date('Y-m-d', time())); $publicationDate = $dateTime->format('Y-m-d'); $entity->set('field_publication_date', $publicationDate); } }
Similar Posts:
- how to Programmatically update an entity reference field in Drupal 8 & 9
- Drupal: Creating a Computed Entity Field
- How to add class to content field link in Drupal 8 / 9
- How to get formatted node creation date in Drupal 8
- How to display in twig node creation date yesterday / today format in drupal 8 / 9
3,120