예제 #1
0
 private function renderFormFieldContent($renderApi, $unit)
 {
     $this->formSubmit = new \FormSubmit();
     $fieldId = 'field' . $unit->getId();
     $properties = $unit->getFormValues();
     $labelText = $properties["fieldLabel"];
     $fieldType = $properties["textType"];
     //input,list,textarea
     $postRequest = $this->getPostValue($unit);
     if ($properties['type'] === \InputType::STRING && $fieldType !== FieldType::TEXTAREA || $properties['type'] === \InputType::EMAIL || $properties['type'] === \InputType::NUMERIC) {
         $formField = new \TextField();
         $elementProperties = $formField->getElementProperties();
         $elementProperties->setId($fieldId);
         $elementProperties->addAttribute("name", $fieldId);
         $elementProperties->addAttribute('value', $postRequest);
         if (isset($properties['type'])) {
             if ($properties['type'] === \InputType::EMAIL) {
                 $elementProperties->addAttribute("type", \InputType::EMAIL);
             }
             if ($properties['type'] === \InputType::NUMERIC) {
                 $elementProperties->addAttribute("type", \InputType::NUMERIC);
             }
         }
     } elseif ($fieldType === FieldType::TEXTAREA) {
         $formField = new \TextareaField();
         $elementProperties = $formField->getElementProperties();
         $elementProperties->setId($fieldId);
         $elementProperties->addAttribute("name", $fieldId);
         $formField->setContent($postRequest);
     }
     $label = new \Label();
     $labelProperties = $label->getElementProperties();
     $labelProperties->addAttribute("for", $fieldId);
     $label->add(new \Span($labelText));
     if ($formField) {
         $wrapper = new \Container();
         $wrapper->add($label);
         $wrapper->add($formField);
         $elementProperties = $formField->getElementProperties();
         if ($this->formSubmit->isValid($renderApi, $unit) && !$this->isValidValue($unit, $postRequest)) {
             $elementProperties->addClass('vf__error');
             $wrapper->add($this->getErrorMessage($unit, $postRequest));
         }
         $this->setRequiredField($renderApi, $unit, $elementProperties);
         $this->setPlaceholderText($renderApi, $unit, $elementProperties);
         echo $wrapper->renderElement();
     }
     $renderApi->renderChildren($unit);
 }