/** * @param form_persistentdocument_field $field * @param block_BlockRequest $request * @param validation_Errors $errors * @return void */ public function validate($field, $request, &$errors) { $value = $request->getParameter($field->getFieldName()); if (is_array($value)) { $isEmpty = f_util_ArrayUtils::isEmpty($value); } else { $isEmpty = f_util_StringUtils::isEmpty($value); } $data = $request->getParameters(); if ($field->getRequired() && $isEmpty) { if ($this->isConditionValid($field, $data)) { $errors->append(f_Locale::translate("&framework.validation.validator.Blank.message;", array('field' => $field->getLabel()))); } } else { if ($field->getRequired() || !$isEmpty) { validation_ValidatorHelper::validate(new validation_Property($field->getLabel(), f_util_Convert::fixDataType($value)), $field->getValidators(), $errors); } } }
/** * @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(); } }