コード例 #1
0
 /**
  * Sets up the fixture.
  *
  * @covers Kunstmaan\PagePartBundle\EventListener\CloneListener::__construct
  */
 protected function setUp()
 {
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->repo = $this->getMockBuilder(PagePartRefRepository::class)->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getRepository')->with($this->equalTo('KunstmaanPagePartBundle:PagePartRef'))->will($this->returnValue($this->repo));
     $this->configurator = new PagePartAdminConfigurator();
     $this->configurator->setContext('main');
     $this->reader = $this->getMock(PagePartConfigurationReaderInterface::class);
     $this->reader->expects($this->any())->method('getPagePartAdminConfigurators')->will($this->returnValue([$this->configurator]));
     $this->reader->expects($this->any())->method('getPagePartContexts')->will($this->returnValue([$this->configurator->getContext()]));
     $this->templateService = $this->getMockBuilder(PageTemplateConfigurationService::class)->disableOriginalConstructor()->getMock();
     $this->object = new CloneListener($this->em, $this->reader, $this->templateService);
 }
コード例 #2
0
 /**
  * @param HasPageTemplateInterface $page
  * @param Request $request
  * @param EntityManagerInterface $em
  * @param PagePartAdminFactory $pagePartAdminFactory
  * @param PageTemplateConfigurationReaderInterface $templateReader
  * @param PagePartConfigurationReaderInterface $pagePartReader
  * @param PageTemplateConfigurationService $pageTemplateConfiguratiorService
  */
 public function __construct(HasPageTemplateInterface $page, Request $request, EntityManagerInterface $em, PagePartAdminFactory $pagePartAdminFactory, PageTemplateConfigurationReaderInterface $templateReader, PagePartConfigurationReaderInterface $pagePartReader, PageTemplateConfigurationService $pageTemplateConfiguratiorService)
 {
     parent::__construct();
     $this->page = $page;
     $this->em = $em;
     $this->request = $request;
     $this->pagePartAdminFactory = $pagePartAdminFactory;
     $this->pageTemplates = $templateReader->getPageTemplates($page);
     $this->pagePartAdminConfigurations = $pagePartReader->getPagePartAdminConfigurators($page);
     $this->pageTemplateConfiguration = $pageTemplateConfiguratiorService->findOrCreateFor($page);
     foreach ($this->getPageTemplate()->getRows() as $row) {
         foreach ($row->getRegions() as $region) {
             $this->processRegion($region);
         }
     }
 }
コード例 #3
0
 /**
  * @param DeepCloneAndSaveEvent $event
  */
 public function postDeepCloneAndSave(DeepCloneAndSaveEvent $event)
 {
     $originalEntity = $event->getEntity();
     if ($originalEntity instanceof HasPagePartsInterface) {
         $clonedEntity = $event->getClonedEntity();
         $contexts = $this->pagePartReader->getPagePartContexts($originalEntity);
         foreach ($contexts as $context) {
             $this->em->getRepository('KunstmaanPagePartBundle:PagePartRef')->copyPageParts($this->em, $originalEntity, $clonedEntity, $context);
         }
     }
     if ($originalEntity instanceof HasPageTemplateInterface) {
         $clonedEntity = $event->getClonedEntity();
         $newPageTemplateConfiguration = clone $this->pageTemplateConfiguratiorService->findOrCreateFor($originalEntity);
         $newPageTemplateConfiguration->setId(null);
         $newPageTemplateConfiguration->setPageId($clonedEntity->getId());
         $this->em->persist($newPageTemplateConfiguration);
     }
 }
コード例 #4
0
 /**
  * @param AdaptFormEvent $event
  */
 public function adaptForm(AdaptFormEvent $event)
 {
     $page = $event->getPage();
     $tabPane = $event->getTabPane();
     if ($page instanceof HasPageTemplateInterface) {
         $pageTemplateWidget = new PageTemplateWidget($page, $event->getRequest(), $this->em, $this->pagePartAdminFactory, $this->templateReader, $this->pagePartReader, $this->pageTemplateConfiguratiorService);
         /* @var Tab $propertiesTab */
         $propertiesTab = $tabPane->getTabByTitle('kuma_node.tab.properties.title');
         if (!is_null($propertiesTab)) {
             $propertiesWidget = $propertiesTab->getWidget();
             $tabPane->removeTab($propertiesTab);
             $tabPane->addTab(new Tab("kuma_pagepart.tab.content.title", new ListWidget(array($propertiesWidget, $pageTemplateWidget))), 0);
         } else {
             $tabPane->addTab(new Tab("kuma_pagepart.tab.content.title", $pageTemplateWidget), 0);
         }
     } else {
         if ($page instanceof HasPagePartsInterface) {
             /* @var HasPagePartsInterface $page */
             $pagePartAdminConfigurators = $this->pagePartReader->getPagePartAdminConfigurators($page);
             foreach ($pagePartAdminConfigurators as $index => $pagePartAdminConfiguration) {
                 $pagePartWidget = new PagePartWidget($page, $event->getRequest(), $this->em, $pagePartAdminConfiguration, $this->pagePartAdminFactory);
                 if ($index == 0) {
                     /* @var Tab $propertiesTab */
                     $propertiesTab = $tabPane->getTabByTitle('kuma_node.tab.properties.title');
                     if (!is_null($propertiesTab)) {
                         $propertiesWidget = $propertiesTab->getWidget();
                         $tabPane->removeTab($propertiesTab);
                         $tabPane->addTab(new Tab($pagePartAdminConfiguration->getName(), new ListWidget(array($propertiesWidget, $pagePartWidget))), 0);
                         continue;
                     }
                 }
                 $tabPane->addTab(new Tab($pagePartAdminConfiguration->getName(), $pagePartWidget), sizeof($tabPane->getTabs()));
             }
         }
     }
 }