Exemplo n.º 1
0
 /**
  * Gives a preview of the form
  *
  * @param int $id
  *
  * @return Response
  * @throws \Exception
  * @throws \Mautic\CoreBundle\Exception\FileNotFoundException
  */
 public function previewAction($id = 0)
 {
     $objectId = empty($id) ? InputHelper::int($this->request->get('id')) : $id;
     $css = InputHelper::raw($this->request->get('css'));
     $model = $this->factory->getModel('form.form');
     $form = $model->getEntity($objectId);
     $customStylesheets = !empty($css) ? explode(',', $css) : array();
     if ($form === null || !$form->isPublished()) {
         throw $this->createNotFoundException($this->factory->getTranslator()->trans('mautic.core.url.error.404'));
     } else {
         $html = $model->getContent($form);
         $model->populateValuesWithGetParameters($form, $html);
         $viewParams = array('content' => $html, 'stylesheets' => $customStylesheets, 'name' => $form->getName());
         $template = $form->getTemplate();
         if (!empty($template)) {
             $theme = $this->factory->getTheme($template);
             if ($theme->getTheme() != $template) {
                 $config = $theme->getConfig();
                 if (in_array('form', $config['features'])) {
                     $template = $theme->getTheme();
                 } else {
                     $template = null;
                 }
             }
         }
     }
     $viewParams['template'] = $template;
     return $this->render('MauticFormBundle::form.html.php', $viewParams);
 }