hook_ENTITY_TYPE_presave(Drupal\Core\Entity\EntityInterface $entity)
Act on a specific type of entity before it is created or updated.
You can get the original entity object from $entity->original when it is an update of the entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity object.
See also
Related topics
- Entity CRUD, editing, and view hooks
- Hooks used in various entity operations.
- Hooks
- Define functions that alter the behavior of Drupal core.
File
- core/lib/Drupal/Core/Entity/entity.api.php, line 923
- Hooks and documentation related to entities.
Code
function hook_ENTITY_TYPE_presave(Drupal\Core\Entity\EntityInterface $entity) { if ($entity->isTranslatable()) { $route_match = \Drupal::routeMatch(); \Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $route_match->getParameter('source_langcode')); } }
Please login to continue.