Skip to content
Snippets Groups Projects
Commit 4a43a3b8 authored by catch's avatar catch
Browse files

Issue #3030086 by amateescu, dhirendra.mishra, Berdir, joshi.rohit100: Clean...

Issue #3030086 by amateescu, dhirendra.mishra, Berdir, joshi.rohit100: Clean up content_translation_entity_presave()
parent d74e36a4
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -462,19 +462,12 @@ function content_translation_form_field_config_edit_form_alter(array &$form, For
* Implements hook_entity_presave().
*/
function content_translation_entity_presave(EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface && $entity->isTranslatable() && !$entity->isNew()) {
if ($entity instanceof ContentEntityInterface && $entity->isTranslatable() && !$entity->isNew() && isset($entity->original)) {
/** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */
$manager = \Drupal::service('content_translation.manager');
if (!$manager->isEnabled($entity->getEntityTypeId(), $entity->bundle())) {
return;
}
// If we are creating a new translation we need to use the source language
// as original language, since source values are the only ones available to
// compare against.
if (!isset($entity->original)) {
$entity->original = \Drupal::entityTypeManager()
->getStorage($entity->entityType())->loadUnchanged($entity->id());
}
$langcode = $entity->language()->getId();
$source_langcode = !$entity->original->hasTranslation($langcode) ? $manager->getTranslationMetadata($entity)->getSource() : NULL;
\Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $langcode, $source_langcode);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment