private function handleForm($formId, $frontController, $uri) { $CMSForm = $this->getCMSForm($formId, $this->localiser); $content = new Content(); $contentType = $this->em->getRepository('SSoneCMSBundle:ContentType')->find($CMSForm['contentTypeId']); $content->setContentType($contentType); $this->bs->contentBlockManager($content); $fieldsRepository = $this->em->getRepository('SSoneCMSBundle:Field'); if ($this->locale == $this->localiser->defaultLocale) { $route = "ssone_cms_frontend_noloco_post"; } else { $route = "ssone_cms_frontend_post"; } $formsService = $this; $form = $frontController->createForm(new ContentTYPEfrontend($CMSForm['buttonText'], $fieldsRepository, $this->cs, $formsService, $this->localiser->locale), $content, array('action' => $frontController->generateUrl($route, array('_locale' => $this->locale, 'uri' => ltrim($uri, "/"), 'contentTypeId' => $contentType->getSecurekey(), "redirect" => $CMSForm['successURL'])))); if ($this->requestStack->getCurrentRequest()->getMethod() == "POST") { //add a content type check to handle multiple forms $form->handleRequest($this->requestStack->getCurrentRequest()); if ($form->isValid()) { //save content $blocks = $this->cs->saveContent($content, $form); $blocks = $blocks[$this->locale]; //send email if ($CMSForm['sendAdminEmailOnSubmit']) { $message = \Swift_Message::newInstance()->setSubject($CMSForm['formTitle'] . ' form submission')->setFrom($CMSForm['adminEmailFromAddress'])->setTo($CMSForm['adminEmailToAddress'])->setBody("hello"); if ($CMSForm['adminEmailHTML']) { $message->setBody($this->twigEngine->render('SSoneCMSThemeBundle:' . $CMSForm['adminEmailHTML'], array("content" => $blocks)))->setContentType("text/html"); } $this->mailer->send($message); } $frontController->redirect = $CMSForm['successURL']; } } $CMSForm['settings'] = $CMSForm; $CMSForm['view'] = $form->createView(); return $CMSForm; }
private function createDefaultContent($domain, $em) { //Create contentType $contentType = new ContentType(); $contentType->setCreatedBy('Install'); $contentType->setModifiedBy('Install'); $contentType->setHideFromMenus(false); $contentType->setName('Default content type'); $contentType->setSlug(array('en' => 'default')); $em->persist($contentType); //Create Field $wyswigFieldType = $this->getDoctrine()->getRepository('SSoneCMSBundle:FieldType')->findOneBy(array('variableName' => 'wysiwyg')); $wyswigField = new Field(); $wyswigField->setName('WYSIWIG Content'); $wyswigField->setCreatedBy('Install'); $wyswigField->setModifiedBy('Install'); $wyswigField->setSort(1); $wyswigField->setVariableName('defaultVariable'); $wyswigField->setIsRepeatable(false); $wyswigField->setIsRequired(false); $wyswigField->setContentTypeByVariable($contentType); $wyswigField->setLabel('Default Label'); $wyswigField->setFieldType($wyswigFieldType); $fieldTypeOptions = $this->getDoctrine()->getRepository('SSoneCMSBundle:FieldSetupOptions')->getAllFieldSetupOptions(); foreach ($fieldTypeOptions as $fieldType) { $fieldTypeOptionsFormatted[$fieldType['fieldTypeVariableName']] = array(); foreach ($fieldType['options'] as $k => $settings) { $value = ''; if ($settings['inputType'] == 'checkbox') { $value = false; } $fieldTypeOptionsFormatted[$fieldType['fieldTypeVariableName']][$k] = $value; } } $wyswigField->setFieldTypeSettings($fieldTypeOptionsFormatted); $em->persist($wyswigField); //Create content $content = new Content(); $content->setCreatedBy('Install'); $content->setModifiedBy('Install'); $content->setName('Default Content'); $content->setContentType($contentType); $content->setSlug(array('en' => 'default')); $em->persist($content); //Create Blocks $block = new Block(); $block->setCreatedBy('Install'); $block->setModifiedBy('Install'); $block->setContent($content); $block->setSort(1); $block->setField($wyswigField); $em->persist($block); //Create BlockFields $blockField = new BlockField(); $blockField->setCreatedBy('Install'); $blockField->setModifiedBy('Install'); $blockField->setBlock($block); $blockField->setFieldContent(array('defaultVariable' => '<p>Welcome to One CMS</p>')); $em->persist($blockField); //Create Menu $menu = new Menu(); $menu->setCreatedBy('Install'); $menu->setModifiedBy('Install'); $menu->setDomain($domain); $menu->setName('Default Menu'); $menu->setSort(1); $menu->setMenuTemplatePosition('A'); $menu->setDrawAllGrandChildren(true); $menu->setGrandChildrenTemplatePosition('A'); $menu->setGrandChildrenRelativePosition('inline'); $em->persist($menu); //Create menuitem $menuItem = new MenuItem(); $menuItem->setCreatedBy('Install'); $menuItem->setModifiedBy('Install'); $menuItem->setContent($content); $menuItem->setPageClass('default'); $menuItem->setName(array('en' => 'Default Home Menu')); $menuItem->setSort(1); $menuItem->setMode('single'); $menuItem->setRoot($menu); $menuItem->setDrawAllGrandChildren(true); $menuItem->setGrandChildrenTemplatePosition('A'); $menuItem->setGrandChildrenRelativePosition('inline'); $menuItem->setHideEmptyCategories(false); $menuItem->setDrawListItemsAsMenuItems(false); $menuItem->setSlug(array('en' => '')); $em->persist($menuItem); $em->flush(); $this->cacheContent($content->getId(), $em); }