/** * @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; }
/** * @param Request $request */ public function bindRequest(Request $request) { $configurationname = $request->get("pagetemplate_template"); $this->pageTemplateConfiguration->setPageTemplate($configurationname); foreach ($this->widgets as $widget) { $widget->bindRequest($request); } }
/** * @covers Kunstmaan\PagePartBundle\EventListener\CloneListener::postDeepCloneAndSave */ public function testClonePageTemplate() { $entity = $this->getMockBuilder('Kunstmaan\\PagePartBundle\\Helper\\HasPageTemplateInterface')->setMethods(array('getId', 'getPageTemplates', 'getPagePartAdminConfigurations'))->getMock(); $entity->expects($this->any())->method('getPagePartAdminConfigurations')->will($this->returnValue(array($this->configurator))); $clone = clone $entity; $entity->expects($this->any())->method('getId')->will($this->returnValue(1)); $clone->expects($this->any())->method('getId')->will($this->returnValue(2)); $this->repo->expects($this->once())->method('copyPageParts')->with($this->em, $entity, $clone, 'main'); $configuration = new PageTemplateConfiguration(); $configuration->setId(1); $configuration->setPageId(1); $this->repo->expects($this->once())->method('findOrCreateFor')->with($this->identicalTo($entity))->will($this->returnValue($configuration)); $newConfiguration = clone $configuration; $newConfiguration->setId(null); $newConfiguration->setPageId($clone->getId()); $this->em->expects($this->once())->method('persist')->with($newConfiguration); $event = new DeepCloneAndSaveEvent($entity, $clone); $this->object->postDeepCloneAndSave($event); }
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(); }
/** * @covers Kunstmaan\PagePartBundle\EventListener\CloneListener::postDeepCloneAndSave */ public function testClonePageTemplate() { $entity = $this->getMock(HasPageTemplateInterface::class); /** @var HasPageTemplateInterface|\PHPUnit_Framework_MockObject_MockObject $clone */ $clone = clone $entity; $entity->expects($this->any())->method('getId')->will($this->returnValue(1)); $clone->expects($this->any())->method('getId')->will($this->returnValue(2)); $this->repo->expects($this->once())->method('copyPageParts')->with($this->em, $entity, $clone, 'main'); $configuration = new PageTemplateConfiguration(); $configuration->setId(1); $configuration->setPageId(1); $this->templateService->expects($this->once())->method('findOrCreateFor')->with($this->identicalTo($entity))->will($this->returnValue($configuration)); $newConfiguration = clone $configuration; $newConfiguration->setId(null); $newConfiguration->setPageId($clone->getId()); $this->em->expects($this->once())->method('persist')->with($newConfiguration); $event = new DeepCloneAndSaveEvent($entity, $clone); $this->object->postDeepCloneAndSave($event); }