public function reverseTransform($string) { if (!$string) { return; } $tags = new ArrayCollection(); foreach (explode(',', $string) as $tagTitle) { $tag = $this->om->getRepository('AppBundle:Tag')->findOneByTitle($tagTitle); if (!$tag && ($tagTranslation = $this->om->getRepository('AppBundle:Translations\\TagTranslation')->findOneByContent($tagTitle))) { $tag = $tagTranslation->getObject(); } if (!$tag) { $tag = new Tag(); $tag->setTitle($tagTitle); $tag->setLocale($this->defaultLocale); foreach ($this->localeCollection as $locale) { if ($locale !== $this->defaultLocale) { $tagTranslation = new TagTranslation(); $tagTranslation->setLocale($locale); $tagTranslation->setField('title'); $tagTranslation->setContent($tagTitle); $tagTranslation->setObject($tag); $tag->addTranslation($tagTranslation); $this->om->persist($tagTranslation); } } $this->om->persist($tag); } $tags->add($tag); } return $tags; }