/** * Load * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $metadata = $manager->getClassMetaData('Unifik\\SystemBundle\\Entity\\Section'); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $sectionHome = new Section(); $sectionHome->setId(1); $sectionHome->setContainer($this->container); $sectionHome->setApp($manager->merge($this->getReference('app-frontend'))); $sectionHome->setCurrentLocale($manager->merge($this->getReference('locale-fr'))->getCode()); $sectionHome->setName('Accueil'); $sectionHome->setActive(true); $sectionHome->setCurrentLocale($manager->merge($this->getReference('locale-en'))->getCode()); $sectionHome->setName('Home'); $sectionHome->setActive(true); $manager->persist($sectionHome); $manager->flush(); $this->addReference('section-home', $sectionHome); }
/** * Return the specific Section for an Exception Event * * @param $id * @param $name * * @return object|Section */ private function getExceptionSection($id, $name) { // TODO Use a tagging system with internal tags. ie: _section_404 $sectionRepository = $this->entityManager->getRepository('UnifikSystemBundle:Section'); $sectionRepository->setCurrentAppName('frontend'); $sectionRepository->setLocale($this->defaultLocale); $section = $sectionRepository->find($id); // Doesn't exist, create the Section if (!$section) { $section = new Section(); $section->setCurrentLocale($this->defaultLocale); $section->setApp($this->entityManager->getRepository('UnifikSystemBundle:App')->find(2)); $section->setId($id); $section->setName($this->translator->trans($name, array(), 'messages', $this->defaultLocale)); $section->setActive(true); $this->entityManager->persist($section); // Force ID $metadata = $this->entityManager->getClassMetaData(get_class($section)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $this->entityManager->flush(); } return $section; }