/**
* Refreshes an entity with real translations
* @param $entity
* @param $language
*
* @author Yohann Marillet
*/
public function refreshEntity($entity, $language)
{
$translatableProperties = $this->getTranslatableProperties($entity);
$setLocaleMethod = $translatableProperties['setLocaleMethod'];
$entity->{$setLocaleMethod}($language);
$this->em->refresh($entity);
if ($this->defaultLocale != $language) {
if (false !== $translatableProperties['usePersonalTranslations']) {
/** @var HasTranslations $entity */
$allTranslations = $entity->getTranslations();
$translations = [];
/** @var AbstractPersonalTranslation $translationEntity */
foreach ($allTranslations as $translationEntity) {
if (!isset($translations[$translationEntity->getLocale()])) {
$translations[$translationEntity->getLocale()] = [];
}
$translations[$translationEntity->getLocale()][$translationEntity->getField()] = $translationEntity->getContent();
}
} else {
$translations = $this->getRepository()->findTranslations($entity);
}
if (!isset($translations[$language])) {
$translations[$language] = $translatableProperties['fields'];
}
foreach ($translations[$language] as $field => $value) {
$setter = Strings::toSetter($field);
$entity->{$setter}($value);
}
}
}