Exemplo n.º 1
0
 /**
  * @param PageDisplayEvent $event
  */
 public function onPageDisplay(PageDisplayEvent $event)
 {
     $content = $event->getContent();
     $page = $event->getPage();
     $regex = '/' . $this->formRegex . '/i';
     preg_match_all($regex, $content, $matches);
     if (count($matches[0])) {
         foreach ($matches[1] as $k => $id) {
             $form = $this->formModel->getEntity($id);
             if ($form !== null && ($form->isPublished(false) || $this->security->hasEntityAccess('form:forms:viewown', 'form:forms:viewother', $form->getCreatedBy()))) {
                 $formHtml = $form->isPublished() ? $this->formModel->getContent($form) : '<div class="mauticform-error">' . $this->translator->trans('mautic.form.form.pagetoken.notpublished') . '</div>';
                 //add the hidden page input
                 $pageInput = "\n<input type=\"hidden\" name=\"mauticform[mauticpage]\" value=\"{$page->getId()}\" />\n";
                 $formHtml = preg_replace('#</form>#', $pageInput . '</form>', $formHtml);
                 //pouplate get parameters
                 //priority populate value order by: query string (parameters) -> with lead
                 if (!$form->getInKioskMode()) {
                     $this->formModel->populateValuesWithLead($form, $formHtml);
                 }
                 $this->formModel->populateValuesWithGetParameters($form, $formHtml);
                 $content = preg_replace('#{form=' . $id . '}#', $formHtml, $content);
             } else {
                 $content = preg_replace('#{form=' . $id . '}#', '', $content);
             }
         }
     }
     $event->setContent($content);
 }