/**
  * @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);
         }
     }
 }
 /**
  * @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);
     }
 }
 /**
  * @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);
 }
 /**
  * @param HasPageTemplateInterface $page The page
  *
  * @return string
  */
 public function getPageTemplate(HasPageTemplateInterface $page)
 {
     return $this->templateConfiguration->findOrCreateFor($page)->getPageTemplate();
 }