Skip to main content
Category:

Example how to set date field programmatically drupal 8


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);
    }
}

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook