Example #1
0
 public function __construct()
 {
     $sl = ServiceLocator::getInstance();
     $config = ConfigFormulario::getInstance();
     $this->repoFormulario = $sl->getRepository($config->getEntityFormulario());
     $this->repoCampoFormulario = $sl->getRepository($config->getEntityCampoFormulario());
     $this->repoCampoFormularioValor = $sl->getRepository($config->getEntityCampoFormularioValor());
 }
Example #2
0
 public function render()
 {
     $config = Registry::get('config');
     $configurable = false;
     if (array_key_exists('general.dynamicForms', $config)) {
         $configurable = (bool) $config['general.dynamicForms'];
     }
     if ($configurable) {
         $configuration = ConfigFormulario::getInstance();
         $entityFormulario = $configuration->getEntityFormulario();
         $entityCampoFormularioValor = $configuration->getEntityCampoFormularioValor();
         $config = $this->findConfiguration($entityFormulario);
         if ($config instanceof $entityFormulario) {
             $this->carregarCamposComplementares($config, $entityCampoFormularioValor);
         }
     }
     if ($this->type === self::TYPE_BASIC) {
         $this->setFormBasic();
     } elseif ($this->type === self::TYPE_INLINE) {
         $this->setFormInline();
     } elseif ($this->type === self::TYPE_HORIZONTAL) {
         $this->setFormHorizontal();
     }
     $attribs = $this->getAttribs();
     $aAttribs = array();
     if (count($attribs) > 0) {
         foreach ($attribs as $key => $value) {
             $aAttribs[] = $key . '="' . $value . '"';
         }
     }
     $itensHTML = '';
     $elements = $this->getElementsOrdered();
     if (count($elements) > 0) {
         foreach ($elements as $element) {
             $element->setLabelWidth($this->getLabelWidth())->setElementClassPrefix($this->getElementClassPrefix());
             if (null === $element->getElementWidth()) {
                 $element->setElementWidth($this->getElementWidth());
             }
             $itensHTML .= $element->render() . PHP_EOL;
         }
     }
     $content = $this->getContent();
     if (!is_null($content)) {
         $itensHTML = sprintf($content, $itensHTML);
     }
     $externalHTML = $this->getExternalHTML();
     if (is_null($externalHTML)) {
         $externalHTML = '%s';
     }
     $formHTML = PHP_EOL . '<form ' . implode(' ', $aAttribs) . '>' . PHP_EOL . $itensHTML . '</form>';
     return sprintf($externalHTML, $formHTML) . PHP_EOL;
 }
Example #3
0
 public function render()
 {
     $form = $this->getForm();
     if (isset($form)) {
         $config = Registry::get('config');
         $configurable = false;
         if (array_key_exists('general.dynamicForms', $config)) {
             $configurable = (bool) $config['general.dynamicForms'];
         }
         if ($this instanceof Element or $this instanceof Multi) {
             if ($configurable) {
                 $this->loadConfiguration();
             }
         }
         if ($configurable) {
             $configuration = ConfigFormulario::getInstance();
             $entityFormulario = $configuration->getEntityFormulario();
             $entityCampoFormularioValor = $configuration->getEntityCampoFormularioValor();
             $config = $form->findConfiguration($entityFormulario);
             if ($config instanceof $entityFormulario) {
                 $form->carregarCamposComplementares($config, $entityCampoFormularioValor);
             }
         }
         $type = $form->getType();
         if ($type === $form::TYPE_BASIC) {
             $this->setElementBasic();
         } elseif ($type === $form::TYPE_INLINE) {
             $this->setElementInline();
         } elseif ($type === $form::TYPE_HORIZONTAL) {
             $this->setElementHorizontal();
         }
     }
     if ($this instanceof \Life\Form\Element\Text || $this instanceof \Life\Form\Element\Password || $this instanceof \Life\Form\Element\Select || $this instanceof \Life\Form\Element\Textarea) {
         $this->addAttrib('class', 'form-control');
     }
     if ($this->isRequired()) {
         $this->setAttrib('required', 'required');
     }
     $label = $this->getLabel();
     $input = $this->renderElement();
     $labelRender = '';
     if ($label) {
         $label->setAttrib('for', $this->getName());
         if ($this->isRequired()) {
             $label->addAttrib('class', 'required');
         }
         $labelRender = $this->getLabel()->render();
     }
     if (is_array($input)) {
         $input = implode($this->getSeparator(), $input);
     }
     $errorHTML = $this->getErrorHTML();
     if (is_null($errorHTML)) {
         $this->setErrorHTML($this->errorHTML);
     }
     $messages = $this->getMessages();
     $aMessages = array();
     if (count($messages) > 0) {
         foreach ($messages as $key => $message) {
             $aMessages[] = $message;
         }
         $errorHTML = $this->getErrorHTML();
         if (isset($errorHTML)) {
             $input .= sprintf($errorHTML, implode('<br />', $aMessages));
         } else {
             $input .= implode('<br />', $aMessages);
         }
     }
     $content = $this->getContent();
     if (!is_null($content)) {
         $input = sprintf($content, $input);
     }
     $externalHTML = $this->getExternalHTML();
     if (!is_null($externalHTML)) {
         return sprintf($externalHTML, $labelRender . $input);
     }
     return $labelRender . $input . PHP_EOL;
 }