public function translate($entity, Metadata $metadata, Property $property, $locale) { if ($locale === $this->defaultLocale) { return; } $accessor = PropertyAccess::createPropertyAccessor(); /** @var Translation $translation */ $translation = $this->getRepository()->findOneBy(['class' => $metadata->getClass(), 'refId' => $entity->getId(), 'property' => $property->getName(), 'locale' => $locale]); $value = ''; if ($translation !== null && $translation->getTranslation() !== null) { $value = $translation->getTranslation(); } $accessor->setValue($entity, $property->getName(), $value); }
public function getTranslations($entity, Metadata $metadata, Property $property) { $data = []; foreach ($this->locales as $locale) { $data[$locale] = null; } if (!$entity instanceof Route) { return $data; } $translationRoutes = $this->getRepository('EnhavoTranslationBundle:TranslationRoute')->findBy(['type' => $entity->getType(), 'typeId' => $entity->getTypeId()]); foreach ($this->locales as $locale) { if ($locale === $this->defaultLocale) { $accessor = PropertyAccess::createPropertyAccessor(); $value = $accessor->getValue($entity, $property->getName()); $data[$locale] = $value; continue; } $value = null; foreach ($translationRoutes as $translationRoute) { if ($translationRoute->getLocale() === $locale) { $value = $translationRoute->getRoute()->getStaticPrefix(); break; } } $data[$locale] = $value; } return $data; }