function hook_ENTITY_TYPE_presave
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_presave()
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_presave()
- 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_ENTITY_TYPE_presave()
Act on a specific type of entity before it is created or updated.
You can get the original entity object from $entity->getOriginal() when it is an update of the entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity object.
See also
Related topics
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1187
Code
function hook_ENTITY_TYPE_presave(\Drupal\Core\Entity\EntityInterface $entity) : void {
if ($entity->isTranslatable()) {
$route_match = \Drupal::routeMatch();
\Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()
->getId(), $route_match->getParameter('source_langcode'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.