/**
  * @param HasPageTemplateInterface $page                 The page
  * @param Request                  $request              The request
  * @param EntityManager            $em                   The entity manager
  * @param KernelInterface          $kernel               The kernel
  * @param FormFactoryInterface     $formFactory          The form factory
  * @param PagePartAdminFactory     $pagePartAdminFactory The page part admin factory
  */
 public function __construct(HasPageTemplateInterface $page, Request $request, EntityManager $em, KernelInterface $kernel, FormFactoryInterface $formFactory, PagePartAdminFactory $pagePartAdminFactory)
 {
     parent::__construct();
     $this->page = $page;
     $this->em = $em;
     $this->request = $request;
     $pageTemplateConfigurationReader = new PageTemplateConfigurationReader($kernel);
     $this->pageTemplates = $pageTemplateConfigurationReader->getPageTemplates($page);
     $pagePartConfigurationReader = new PagePartConfigurationReader($kernel);
     $this->pagePartAdminConfigurations = $pagePartConfigurationReader->getPagePartAdminConfigurators($this->page);
     $repo = $this->em->getRepository('KunstmaanPagePartBundle:PageTemplateConfiguration');
     $repo->setContainer($kernel->getContainer());
     $this->pageTemplateConfiguration = $repo->findOrCreateFor($page);
     foreach ($this->getPageTemplate()->getRows() as $row) {
         foreach ($row->getRegions() as $region) {
             $pagePartAdminConfiguration = null;
             foreach ($this->pagePartAdminConfigurations as $ppac) {
                 if ($ppac->getContext() == $region->getName()) {
                     $pagePartAdminConfiguration = $ppac;
                 }
             }
             if ($pagePartAdminConfiguration !== null) {
                 $pagePartWidget = new PagePartWidget($page, $this->request, $this->em, $pagePartAdminConfiguration, $formFactory, $pagePartAdminFactory);
                 $this->widgets[$region->getName()] = $pagePartWidget;
             }
         }
     }
 }
 /**
  * @param array                    $twigContext The twig context
  * @param HasPageTemplateInterface $page        The page
  * @param array                    $parameters  Some extra parameters
  *
  * @return string
  */
 public function renderPageTemplate(array $twigContext, HasPageTemplateInterface $page, array $parameters = array())
 {
     $pageTemplateConfigurationReader = new PageTemplateConfigurationReader($this->kernel);
     $pageTemplates = $pageTemplateConfigurationReader->getPageTemplates($page);
     /* @var $pageTemplate PageTemplate */
     $pageTemplate = $pageTemplates[$this->getPageTemplate($page)];
     $template = $this->environment->loadTemplate($pageTemplate->getTemplate());
     return $template->render(array_merge($parameters, $twigContext));
 }
 /**
  * @param HasPageTemplateInterface $page The page
  *
  * @return PageTemplateConfiguration
  */
 public function findOrCreateFor(HasPageTemplateInterface $page)
 {
     $pageTemplateConfiguration = $this->findFor($page);
     if (is_null($pageTemplateConfiguration)) {
         $pageTemplateConfigurationReader = new PageTemplateConfigurationReader($this->container->get('kernel'));
         $pageTemplates = $this->pageTemplates = $pageTemplateConfigurationReader->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 HasPageTemplateInterface $page                 The page
  * @param Request                  $request              The request
  * @param EntityManager            $em                   The entity manager
  * @param KernelInterface          $kernel               The kernel
  * @param FormFactoryInterface     $formFactory          The form factory
  * @param PagePartAdminFactory     $pagePartAdminFactory The page part admin factory
  */
 public function __construct(HasPageTemplateInterface $page, Request $request, EntityManager $em, KernelInterface $kernel, FormFactoryInterface $formFactory, PagePartAdminFactory $pagePartAdminFactory)
 {
     parent::__construct();
     $this->page = $page;
     $this->em = $em;
     $this->request = $request;
     $this->formFactory = $formFactory;
     $this->pagePartAdminFactory = $pagePartAdminFactory;
     $pageTemplateConfigurationReader = new PageTemplateConfigurationReader($kernel);
     $this->pageTemplates = $pageTemplateConfigurationReader->getPageTemplates($page);
     $pagePartConfigurationReader = new PagePartConfigurationReader($kernel);
     $this->pagePartAdminConfigurations = $pagePartConfigurationReader->getPagePartAdminConfigurators($this->page);
     $repo = $this->em->getRepository('KunstmaanPagePartBundle:PageTemplateConfiguration');
     $repo->setContainer($kernel->getContainer());
     $this->pageTemplateConfiguration = $repo->findOrCreateFor($page);
     foreach ($this->getPageTemplate()->getRows() as $row) {
         foreach ($row->getRegions() as $region) {
             $this->processRegion($region);
         }
     }
 }