Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

How to change entity before it is created or updated.


Example How to change entity before it is created or updated using hook_entity_presave().


function MODULE_entity_presave(EntityInterface $entity)
    if ($entity->getEntityTypeId() == 'node') {
        if ($entity->getType() == 'article') {
            $entity->set('title', $title);


Example 2:

 * Implements hook_entity_presave().
function YOUR_MODULE_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
  switch ($entity->bundle()) {
    // Here you modify only your day content type
    case 'day':
      // Setting the title with the value of field_date.


Add new comment

Restricted HTML


Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon