/** * @param AdaptFormEvent $event */ public function adaptForm(AdaptFormEvent $event) { if ($event->getPage() instanceof HasNodeInterface) { /* @var Seo $seo */ $seo = $this->em->getRepository('KunstmaanSeoBundle:Seo')->findOrCreateFor($event->getPage()); $seoWidget = new FormWidget(); $seoWidget->addType('seo', new SeoType(), $seo); $event->getTabPane()->addTab(new Tab('SEO', $seoWidget)); $socialWidget = new FormWidget(); $socialWidget->addType('social', new SocialType(), $seo); $event->getTabPane()->addTab(new Tab('Social', $socialWidget)); } }
/** * @param AdaptFormEvent $event */ public function adaptForm(AdaptFormEvent $event) { if ($event->getPage() instanceof HasNodeInterface && !$event->getPage()->isStructureNode()) { /* @var Seo $seo */ $seo = $this->em->getRepository('KunstmaanSeoBundle:Seo')->findOrCreateFor($event->getPage()); $seoWidget = new FormWidget(); $seoWidget->addType('seo', new SeoType(), $seo); $event->getTabPane()->addTab(new Tab('seo.tab.seo.title', $seoWidget)); $socialWidget = new FormWidget(); $socialWidget->addType('social', new SocialType(), $seo); $socialWidget->setTemplate('KunstmaanSeoBundle:Admin\\Social:social.html.twig'); $event->getTabPane()->addTab(new Tab('seo.tab.social.title', $socialWidget)); } }
public function __construct(PageMediaCollectionAdminType $type, Collection $mediaSet) { parent::__construct(['media_set' => $type]); $this->type = $type; $this->mediaSet = $mediaSet; $this->toDelete = $mediaSet->toArray(); }
/** * @param FormBuilderInterface $builder The form builder */ public function buildForm(FormBuilderInterface $builder) { parent::buildForm($builder); $data = $builder->getData(); $data['node_search'] = $this->nodeSearch; $builder->setData($data); }
/** * @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 FormView $formView * * @return array */ public function getFormErrors(FormView $formView) { $errors = parent::getFormErrors($formView); foreach ($this->widgets as $widget) { $errors = array_merge($errors, $widget->getFormErrors($formView)); } return $errors; }
/** * @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 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); } } }
/** * @param FormView $formView * * @return array */ public function getFormErrors(FormView $formView) { $errors = parent::getFormErrors($formView); $formHelper = $this->getFormHelper(); if (isset($formView['pagepartadmin_' . $this->pagePartAdmin->getContext()])) { $errors = array_merge($errors, $formHelper->getRecursiveErrorMessages($formView['pagepartadmin_' . $this->pagePartAdmin->getContext()])); } return $errors; }
/** * @param int $id The node id * @param string $subaction The subaction (draft|public) * * @throws AccessDeniedException * @Route("/{id}/{subaction}", requirements={"_method" = "GET|POST", "id" = "\d+"}, defaults={"subaction" = "public"}, name="KunstmaanNodeBundle_nodes_edit") * @Template() * * @return RedirectResponse|array */ public function editAction($id, $subaction) { $this->init(); /* @var Node $node */ $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id); $this->checkPermission($node, PermissionMap::PERMISSION_EDIT); $request = $this->getRequest(); $tabPane = new TabPane('todo', $request, $this->container->get('form.factory')); $nodeTranslation = $node->getNodeTranslation($this->locale, true); if (!$nodeTranslation) { //try to find a parent node with the correct translation, if there is none allow copy. //if there is a parent but it doesn't have the language to copy to don't allow it $parentNode = $node->getParent(); if ($parentNode) { $parentNodeTranslation = $parentNode->getNodeTranslation($this->locale, true); $parentsAreOk = false; if ($parentNodeTranslation) { $parentsAreOk = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->hasParentNodeTranslationsForLanguage($node->getParent()->getNodeTranslation($this->locale, true), $this->locale); } } else { $parentsAreOk = true; } return $this->render('KunstmaanNodeBundle:NodeAdmin:pagenottranslated.html.twig', array('node' => $node, 'nodeTranslations' => $node->getNodeTranslations(true), 'copyfromotherlanguages' => $parentsAreOk)); } $nodeVersion = $nodeTranslation->getPublicNodeVersion(); $draftNodeVersion = $nodeTranslation->getNodeVersion('draft'); /* @var HasNodeInterface $page */ $page = null; $draft = $subaction == 'draft'; $saveAsDraft = $request->get('saveasdraft'); if (!$draft && !empty($saveAsDraft) || $draft && is_null($draftNodeVersion)) { // Create a new draft version $draft = true; $subaction = "draft"; $page = $nodeVersion->getRef($this->em); $nodeVersion = $this->createDraftVersion($page, $nodeTranslation, $nodeVersion); $draftNodeVersion = $nodeVersion; } elseif ($draft) { $nodeVersion = $draftNodeVersion; $page = $nodeVersion->getRef($this->em); } else { if ($request->getMethod() == 'POST') { //Check the version timeout and make a new nodeversion if the timeout is passed $thresholdDate = date("Y-m-d H:i:s", time() - $this->container->getParameter("kunstmaan_node.version_timeout")); $updatedDate = date("Y-m-d H:i:s", strtotime($nodeVersion->getUpdated()->format("Y-m-d H:i:s"))); if ($thresholdDate >= $updatedDate) { $page = $nodeVersion->getRef($this->em); if ($nodeVersion == $nodeTranslation->getPublicNodeVersion()) { $this->get('kunstmaan_node.admin_node.publisher')->createPublicVersion($page, $nodeTranslation, $nodeVersion, $this->user); } else { $this->createDraftVersion($page, $nodeTranslation, $nodeVersion); } } } $page = $nodeVersion->getRef($this->em); } $isStructureNode = $page->isStructureNode(); $menubuilder = $this->get('kunstmaan_node.actions_menu_builder'); $menubuilder->setActiveNodeVersion($nodeVersion); $menubuilder->setEditableNode(!$isStructureNode); // Building the form $propertiesWidget = new FormWidget(); $pageAdminType = $page->getDefaultAdminType(); if (!is_object($pageAdminType) && is_string($pageAdminType)) { $pageAdminType = $this->container->get($pageAdminType); } $propertiesWidget->addType('main', $pageAdminType, $page); $nodeAdminType = $node->getDefaultAdminType(); if (!is_object($nodeAdminType) && is_string($nodeAdminType)) { $nodeAdminType = $this->container->get($nodeAdminType); } $propertiesWidget->addType('node', $nodeAdminType, $node); $tabPane->addTab(new Tab('Properties', $propertiesWidget)); // Menu tab if (!$isStructureNode) { $menuWidget = new FormWidget(); $menuWidget->addType('menunodetranslation', new NodeMenuTabTranslationAdminType(), $nodeTranslation); $menuWidget->addType('menunode', new NodeMenuTabAdminType(), $node); $tabPane->addTab(new Tab('Menu', $menuWidget)); $this->get('event_dispatcher')->dispatch(Events::ADAPT_FORM, new AdaptFormEvent($request, $tabPane, $page, $node, $nodeTranslation, $nodeVersion)); } $tabPane->buildForm(); if ($request->getMethod() == 'POST') { $tabPane->bindRequest($request); if ($tabPane->isValid()) { $this->get('event_dispatcher')->dispatch(Events::PRE_PERSIST, new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)); $nodeTranslation->setTitle($page->getTitle()); if ($isStructureNode) { $nodeTranslation->setSlug(''); } $nodeVersion->setUpdated(new DateTime()); if ($nodeVersion->getType() == 'public') { $nodeTranslation->setUpdated($nodeVersion->getUpdated()); } $this->em->persist($nodeTranslation); $this->em->persist($nodeVersion); $tabPane->persist($this->em); $this->em->flush(); $this->get('event_dispatcher')->dispatch(Events::POST_PERSIST, new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)); $this->get('session')->getFlashBag()->add('success', 'The page has been edited'); $params = array('id' => $node->getId(), 'subaction' => $subaction, 'currenttab' => $tabPane->getActiveTab()); $params = array_merge($params, $tabPane->getExtraParams($request)); return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', $params)); } } $nodeVersions = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')->findBy(array('nodeTranslation' => $nodeTranslation), array('updated' => 'ASC')); $queuedNodeTranslationAction = $this->em->getRepository('KunstmaanNodeBundle:QueuedNodeTranslationAction')->findOneBy(array('nodeTranslation' => $nodeTranslation)); return array('page' => $page, 'entityname' => ClassLookup::getClass($page), 'nodeVersions' => $nodeVersions, 'node' => $node, 'nodeTranslation' => $nodeTranslation, 'draft' => $draft, 'draftNodeVersion' => $draftNodeVersion, 'subaction' => $subaction, 'tabPane' => $tabPane, 'editmode' => true, 'queuedNodeTranslationAction' => $queuedNodeTranslationAction); }
/** * @param Request $request * * @return array */ public function getExtraParams(Request $request) { return $this->widget->getExtraParams($request); }