Explorar o código

Merge remote-tracking branch 'epf/master'

gedi %!s(int64=13) %!d(string=hai) anos
pai
achega
47a2c2caad
Modificáronse 1 ficheiros con 19 adicións e 13 borrados
  1. 19 13
      lib/Gedmo/Translatable/TranslatableListener.php

+ 19 - 13
lib/Gedmo/Translatable/TranslatableListener.php

@@ -532,18 +532,23 @@ class TranslatableListener extends MappedEventSubscriber
             if ($translation) {
                 // set the translated field, take value using reflection
                 $value = $wrapped->getPropertyValue($field);
-                $translation->setContent($ea->getTranslationValue($object, $field));
-                if ($isInsert && !$objectId && !$ea->usesPersonalTranslation($translationClass)) {
-                    // if we do not have the primary key yet available
-                    // keep this translation in memory to insert it later with foreign key
-                    $this->pendingTranslationInserts[spl_object_hash($object)][] = $translation;
-                } else {
-                    // persist and compute change set for translation
-                    if ($wasPersistedSeparetely) {
-                        $ea->recomputeSingleObjectChangeset($uow, $translationMetadata, $translation);
-                    } else {
-                        $om->persist($translation);
-                        $uow->computeChangeSet($translationMetadata, $translation);
+                $content = $ea->getTranslationValue($object, $field);
+                $translation->setContent($content);
+                if (!empty($content)) {
+                    if ($isInsert && !$objectId && !$ea->usesPersonalTranslation($translationClass)) {
+                        // if we do not have the primary key yet available
+                        // keep this translation in memory to insert it later with foreign key
+                        $this->pendingTranslationInserts[spl_object_hash($object)][] = $translation;
+                    }
+                    else {
+                        // persist and compute change set for translation
+                        if ($wasPersistedSeparetely) {
+                            $ea->recomputeSingleObjectChangeset($uow, $translationMetadata, $translation);
+                        }
+                        else {
+                            $om->persist($translation);
+                            $uow->computeChangeSet($translationMetadata, $translation);
+                        }
                     }
                 }
             }
@@ -556,7 +561,8 @@ class TranslatableListener extends MappedEventSubscriber
             foreach ($changeSet as $field => $changes) {
                 if (in_array($field, $translatableFields)) {
                     if ($locale !== $this->defaultLocale) {
-                        $wrapped->setPropertyValue($field, $changes[0]);
+                        // Useless : don't change anything
+                        //$wrapped->setPropertyValue($field, $changes[1]);
                         $ea->setOriginalObjectProperty($uow, $oid, $field, $changes[0]);
                         unset($modifiedChangeSet[$field]);
                     }