function hook_ENTITY_TYPE_presave
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 914
- 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')); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/function/hook_ENTITY_TYPE_presave/8.1.x