/**
  * @param HasPageTemplateInterface $page The page
  *
  * @return PageTemplateConfiguration
  */
 public function findOrCreateFor(HasPageTemplateInterface $page)
 {
     $pageTemplateConfiguration = $this->repo->findFor($page);
     if (null === $pageTemplateConfiguration) {
         $pageTemplates = $this->reader->getPageTemplates($page);
         $names = array_keys($pageTemplates);
         $defaultPageTemplate = $pageTemplates[$names[0]];
         $pageTemplateConfiguration = new PageTemplateConfiguration();
         $pageTemplateConfiguration->setPageId($page->getId());
         $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page));
         $pageTemplateConfiguration->setPageTemplate($defaultPageTemplate->getName());
     }
     return $pageTemplateConfiguration;
 }
Exemplo n.º 2
0
 public function postFlushBuild(Fixture $fixture)
 {
     $entities = $fixture->getAdditionalEntities();
     $fixtureParams = $fixture->getParameters();
     foreach ($fixture->getTranslations() as $language => $data) {
         /** @var HasNodeInterface $page */
         $page = $entities[$fixture->getName() . '_' . $language];
         /** @var NodeTranslation $translationNode */
         $translationNode = $entities['translationNode_' . $language];
         $pagecreator = array_key_exists('creator', $fixtureParams) ? $fixtureParams['creator'] : 'pagecreator';
         $creator = $this->userRepo->findOneBy(array('username' => $pagecreator));
         $nodeVersion = new NodeVersion();
         $nodeVersion->setNodeTranslation($translationNode);
         $nodeVersion->setType('public');
         $nodeVersion->setOwner($creator);
         $nodeVersion->setRef($page);
         $translationNode->setPublicNodeVersion($nodeVersion);
         if (isset($fixtureParams['template'])) {
             $pageTemplateConfiguration = new PageTemplateConfiguration();
             $pageTemplateConfiguration->setPageId($page->getId());
             $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page));
             $pageTemplateConfiguration->setPageTemplate($fixtureParams['template']);
             $this->manager->persist($pageTemplateConfiguration);
         }
         $this->manager->persist($nodeVersion);
         $this->manager->persist($translationNode);
     }
     $this->manager->flush();
 }
 /**
  * @param mixed(Node|string) $nodeOrInternalName
  * @param string $language
  * @param string $templateName
  */
 public function setPageTemplate($nodeOrInternalName, $language, $templateName)
 {
     $node = $this->getNode($nodeOrInternalName);
     /** @var $translation NodeTranslation */
     $translation = $node->getNodeTranslation($language, true);
     /** @var HasPageTemplateInterface|EntityInterface $page */
     $page = $translation->getRef($this->em);
     /** @var PageTemplateConfigurationRepository $repo */
     $repo = $this->em->getRepository('KunstmaanPagePartBundle:PageTemplateConfiguration');
     $pageTemplateConfiguration = $repo->findFor($page);
     if ($pageTemplateConfiguration) {
         $pageTemplateConfiguration->setPageTemplate($templateName);
     } else {
         $pageTemplateConfiguration = new PageTemplateConfiguration();
         $pageTemplateConfiguration->setPageId($page->getId());
         $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page));
         $pageTemplateConfiguration->setPageTemplate($templateName);
     }
     $this->em->persist($pageTemplateConfiguration);
     $this->em->flush();
 }