function hook_ENTITY_TYPE_presave
Same name in other branches
- 9 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()
- 11.x 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->original when it is an update of the entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity object.
See also
Related topics
4 functions implement hook_ENTITY_TYPE_presave()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- comment_entity_view_display_presave in core/
modules/ comment/ comment.module - Implements hook_ENTITY_TYPE_presave() for entity_view_display entities.
- field_ui_entity_form_mode_presave in core/
modules/ field_ui/ field_ui.module - Implements hook_entity_form_mode_presave().
- field_ui_entity_view_mode_presave in core/
modules/ field_ui/ field_ui.module - Implements hook_entity_view_mode_presave().
- system_entity_form_display_presave in core/
modules/ system/ system.module - Implements hook_ENTITY_TYPE_presave() for entity_form_display entities.
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1118
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'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.