hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity)
Act on an 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 904
- Hooks and documentation related to entities.
Code
1 2 3 4 5 6 | function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity ) { if ( $entity instanceof ContentEntityInterface && $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.