Example How to change entity before it is created or updated using hook_entity_presave().
First example
function MODULE_entity_presave(EntityInterface $entity) { if ($entity->getEntityTypeId() == 'node') { if ($entity->getType() == 'article') { $entity->set('title', $title); } } }
Second example:
Similar Posts:
- how to Programmatically update an entity reference field in Drupal 8 & 9
- How to create a custom page programmatically in Drupal 8
- change canonical URL in drupal 8 & 9
- How to get the address / url / uri of a file from a File entity in drupal?
621