Exemplo n.º 1
0
 /**
  * Prepare the form
  */
 protected function _boot()
 {
     $formDoc = DocBlockParser::fromObject($this->getDataObject());
     $labelPosition = FormElement::LABEL_BEFORE;
     $defaultTags = [];
     foreach ($formDoc->getTags() as $tag => $values) {
         foreach ($values as $value) {
             if (Strings::startsWith($tag, 'element', false)) {
                 $defaultTags[substr($tag, 7)] = $value;
             }
         }
     }
     foreach ($this->_processPublicProperties() as $property) {
         if (isset($this->_elements[$property])) {
             continue;
         }
         static::$_propDocBlocks[$this->_calledClass][$property] = $docblock = DocBlockParser::fromProperty($this->getDataObject(), $property);
         //Setup the type
         $type = $docblock->getTagFailover(["inputType", "type", "input"]);
         if ($type === null) {
             $type = FormElement::calculateType($property);
         }
         //Setup the label
         $label = $docblock->getTag("label");
         if ($label === null) {
             $label = Strings::humanize($property);
         }
         $element = new FormElement($this, $property, $type, $label, $labelPosition);
         foreach ($defaultTags as $tag => $value) {
             $element->processDocBlockTag($tag, $value);
         }
         $element->setDataObject($this->getDataObject(), $property);
         $this->_aliases[$element->getName()] = $property;
         foreach ($docblock->getTags() as $tag => $values) {
             foreach ($values as $value) {
                 $element->processDocBlockTag($tag, $value);
             }
         }
         $this->_elements[$property] = $element;
     }
     if ($this->_enableCsrf) {
         $this->_buildCsrf();
     } else {
         $this->getElement($this->_csrfField)->setRenderer(new FormElementRenderer(''));
     }
 }
Exemplo n.º 2
0
 public function renderInput(FormElement $element)
 {
     $value = Strings::escape($element->getValue());
     if ($element->getType() === FormElement::PASSWORD) {
         $value = "";
     }
     $out = '<input';
     $out .= $this->_renderAttributes($element, ["type" => $element->getType(), "value" => $value]);
     $out .= '/>';
     return $out;
 }