/** * @param Context $context * @param Request $request */ public function _execute($context, $request) { $form = $this->getDocumentInstanceFromRequest($request); $request->setAttribute('form', $form); // determine output type if ($request->hasParameter('output')) { $output = ucfirst(strtolower($request->getParameter('output'))); } if (empty($output)) { $output = ucfirst(K::HTML); } if ($request->getParameter('all') == 'all') { $request->setAttribute('all', 'all'); } $className = 'form_Export' . $output . 'View'; if (!f_util_ClassUtils::classExists($className)) { throw new Exception('Unable to format output as "' . $output . '".'); } $request->setAttribute('form', $form); return $output; }
/** * @param array<TreeNode> $nodes * @param array $contents * @param block_BlockRequest $request * @param form_persistentdocument_baseform $form * @since 2.0.2 * @deprecated */ public function buildContentsFromRequest($nodes, &$contents, $request, $form) { $parameters = $request->getParameters(); $eventParam = array('form' => $form, 'parameters' => &$parameters, 'isPosted' => $this->isPostedFormId($form->getId(), $request)); f_event_EventManager::dispatchEvent(self::FORM_INIT_DATA_EVENT_NAME, $this, $eventParam); $request->setParametersByRef($parameters); foreach ($nodes as $node) { // $document is a form_persistentdocument_field $document = $node->getPersistentDocument(); $html = ''; if ($document instanceof form_persistentdocument_group) { $templateObject = TemplateLoader::getInstance()->setPackageName('modules_form')->setDirectory('templates/markup/' . $form->getMarkup())->load('Form-Group'); $elements = array(); $this->buildContentsFromRequest($node->getChildren(), $elements, $request, $form); $attributes = array('id' => $document->getId(), 'label' => $document->getLabel(), 'description' => $document->getDescription(), 'elements' => $elements); $html = $templateObject->setAttribute('group', $attributes); } else { if ($document instanceof form_persistentdocument_field) { $templateObject = TemplateLoader::getInstance()->setPackageName('modules_form')->setDirectory('templates/markup/' . $form->getMarkup())->load($document->getSurroundingTemplate()); $html = FormHelper::fromFieldDocument($document, isset($parameters[$document->getFieldName()]) ? $parameters[$document->getFieldName()] : $document->getDefaultValue()); $attributes = array('id' => $document->getId(), 'label' => $document->getLabel(), 'description' => $document->getHelpText(), 'required' => $document->getRequired(), 'display' => f_util_ClassUtils::methodExists($document, 'getDisplay') ? $document->getDisplay() : '', 'html' => $html); } else { if ($document instanceof form_persistentdocument_freecontent) { $templateObject = TemplateLoader::getInstance()->setPackageName('modules_form')->setDirectory('templates/markup/' . $form->getMarkup())->load('Form-FreeContent'); $attributes = array('id' => $document->getId(), 'label' => $document->getLabel(), 'description' => $document->getText(), 'required' => false, 'html' => ''); } } $templateObject->setAttribute('field', $attributes); } $contents[$document->getId()] = $templateObject->execute(); } }
/** * @param form_persistentdocument_field $field * @param string $value */ public static function fromFieldDocument($field, $value = '') { if ($field instanceof form_persistentdocument_field) { $type = ucfirst(substr(get_class($field), strlen('form_persistentdocument_'))); $methodName = 'from' . $type . 'FieldDocument'; if (f_util_ClassUtils::methodExists(get_class(), $methodName)) { return self::$methodName($field, $value); } } return "Unknown field type: " . get_class($field, $value); }
/** * @param array<TreeNode> $nodes * @param block_BlockRequest $request * @param form_persistentdocument_baseform $form * @return array */ protected function getContentsFromRequest($nodes, $request, $form) { $contents = array(); $markup = $form->getMarkup(); foreach ($nodes as $node) { $document = $node->getPersistentDocument(); if ($document instanceof form_persistentdocument_group) { $templateObject = TemplateLoader::getInstance()->setPackageName('modules_form')->setDirectory('templates/markup/' . $markup)->load('Form-Group'); $elements = $this->getContentsFromRequest($node->getChildren(), $contents, $request, $markup); $attributes = array('id' => $document->getId(), 'label' => $document->getLabel(), 'description' => $document->getDescription(), 'elements' => $elements); } else { if ($document instanceof form_persistentdocument_field) { $templateObject = TemplateLoader::getInstance()->setPackageName('modules_form')->setDirectory('templates/markup/' . $markup)->load($document->getSurroundingTemplate()); $html = FormHelper::fromFieldDocument($document, $request->hasParameter($document->getFieldName()) ? $request->getParameter($document->getFieldName()) : $document->getDefaultValue()); $attributes = array('id' => $document->getId(), 'label' => $document->getLabel(), 'description' => $document->getHelpText(), 'required' => $document->getRequired(), 'display' => f_util_ClassUtils::methodExists($document, 'getDisplay') ? $document->getDisplay() : '', 'html' => $html); } else { if ($document instanceof form_persistentdocument_freecontent) { $templateObject = TemplateLoader::getInstance()->setPackageName('modules_form')->setDirectory('templates/markup/' . $markup)->load('Form-FreeContent'); $attributes = array('id' => $document->getId(), 'label' => $document->getLabel(), 'description' => $document->getText(), 'required' => false, 'html' => ''); } } $templateObject->setAttribute('field', $attributes); } $contents[$document->getId()] = $templateObject->execute(); } return $contents; }
/** * @param block_BlockContext $context * @param block_BlockRequest $request * @return String the view name */ public function execute($context, $request) { $id = $this->getFormId(); if (empty($id)) { return block_BlockView::NONE; } $form = DocumentHelper::getDocumentInstance($id); if (!$form->isPublished()) { return block_BlockView::NONE; } $form->getDocumentNode()->getDescendents(); $this->setParameter('form', $form); if ($context->inBackofficeMode()) { return block_BlockView::DUMMY; } if ($request->hasParameter("receiverIds")) { $receiverIds = explode(",", $request->getParameter("receiverIds")); $receiverLabels = array(); foreach ($receiverIds as $receiverId) { if (is_numeric($receiverId)) { try { $receiver = DocumentHelper::getDocumentInstance($receiverId); $receiverLabels[] = $receiver->getLabel(); } catch (Exception $e) { Framework::exception($e); $receiverLabels[] = $receiverId; } } elseif (f_util_StringUtils::isNotEmpty($receiverId)) { $receiverLabels[] = $receiverId; } } $this->setParameter("receiverLabels", $receiverLabels); } if ($this->isSuccess($context, $request)) { $view = block_BlockView::SUCCESS; } else { if ($this->isFormPosted($request)) { $fs = form_FormService::getInstance(); try { $fs->saveFormData($form, $request); $user = $context->getGlobalContext()->getUser(); $user->setAttribute('form_success_parameters_' . $form->getId(), $request->getParameters()); $view = block_BlockView::SUCCESS; } catch (form_FormValidationException $e) { $this->setParameter('errors', $e->getErrorCollection()); $view = block_BlockView::INPUT; } } else { $view = block_BlockView::INPUT; } } // Calls the BlockFormDecorator if present. $formId = $form->getFormid(); $matches = null; if (preg_match('#^modules_([a-z]+)/([a-z]+)$#', $formId, $matches)) { $extendClassName = $matches[1] . '_BlockForm' . ucfirst($matches[2]) . 'Decorator'; if (f_util_ClassUtils::classExists($extendClassName)) { $instance = new $extendClassName($this); if ($instance instanceof form_BlockFormDecorator) { $instance->execute($context, $request); } else { Framework::warn("\"{$extendClassName}\" is not an instance of \"block_BlockDecorator\": form \"{$formId}\" won't be decorated."); } } } return $view; }