Ejemplo n.º 1
0
 /**
  * @param Element $element
  * @return string
  */
 public function render(Element $element)
 {
     if ($element instanceof Element\Hidden) {
         return $this->elementHelper->render($element);
     } else {
         $replaces = ['{{before}}' => '', '{{after}}' => '', '{{error_messages}}' => '', '{{elem_markup}}' => ''];
         $elemClass = $element->getAttribute('class');
         $elemType = $element->getAttribute('type');
         $placeholder = $element->getAttribute('placeholder');
         if (!$placeholder) {
             $element->setAttribute('placeholder', $element->getLabel());
         }
         if (!in_array($elemType, $this->excludedFormControlClass)) {
             $element->setAttribute('class', join(' ', ['form-control', $elemClass]));
         }
         if (method_exists($element, 'getInputSpecification')) {
             $spec = $element->getInputSpecification();
             if (isset($spec['required']) && $spec['required']) {
                 $element->setAttribute('required', 'required');
             }
         }
         if ($errorMessages = $this->errorHelper->render($element)) {
             $replaces['{{error_messages}}'] = sprintf('<div class="error-messages">%s</div>', $errorMessages);
         }
         if ($before = $element->getOption('before')) {
             $replaces['{{before}}'] = $before;
         }
         if ($after = $element->getOption('after')) {
             $replaces['{{after}}'] = $after;
         }
         $replaces['{{elem_markup}}'] = $this->elementHelper->render($element);
         return strtr($this->template, $replaces);
     }
 }
 public function render(ElementInterface $element)
 {
     $view = $this->getView();
     $formLabel = new Helper\FormLabel();
     $formElement = new Helper\FormFile();
     $formElement->setView($view);
     $formErrors = new Helper\FormElementErrors();
     $formErrors->setView($view);
     $html = '<tr>' . '<th align="right">' . $formLabel($element) . '</th>' . '<td width="10px">&nbsp;</td>' . '<td>' . $formElement($element, Escaper\AbstractHelper::RECURSE_ARRAY) . '<span class="form-errors">' . $formErrors($element) . '</span>' . '</td></tr>' . PHP_EOL;
     return $html;
 }
 public function render(Element\Radio $element, $uncheckedValue)
 {
     $html = '';
     $view = $this->getView();
     $formLabel = new Helper\FormLabel();
     $formRadio = new Helper\FormRadio();
     $formRadio->setView($view)->setUseHiddenElement(TRUE)->setUncheckedValue($uncheckedValue)->setSeparator("</td>\n<td>");
     $formErrors = new Helper\FormElementErrors();
     $formErrors->setView($view);
     $html .= '<tr>' . '<th align="right">' . $formLabel($element) . '</th>' . '<td width="10px">&nbsp;</td>' . '<td>' . '<table width="100%">' . '<tr>' . '<td>' . $formRadio($element) . '</td>' . '</tr>' . '</table>' . PHP_EOL . '<span class="form-errors">' . $formErrors($element) . '</span>' . '</td>' . '</tr>' . PHP_EOL;
     return $html;
 }
Ejemplo n.º 4
0
 /**
  * @param Element $element
  * @return string
  */
 public function render(Element $element)
 {
     if ($element instanceof Element\Hidden) {
         return $this->elementHelper->render($element);
     } else {
         $replaces = ['{{before}}' => '', '{{after}}' => '', '{{row_class}}' => $this->options['row_class'], '{{label_text}}' => $element->getLabel(), '{{label_class}}' => '', '{{elem_markup}}' => '', '{{error_messages}}' => '', '{{help_text}}' => '', '{{feedback}}' => '', '{{elem_id}}' => ''];
         $elemClass = $element->getAttribute('class');
         $elemType = $element->getAttribute('type');
         if (!in_array($elemType, $this->excludedFormControlClass)) {
             $element->setAttribute('class', join(' ', ['form-control', $elemClass]));
         }
         if (method_exists($element, 'getInputSpecification')) {
             $spec = $element->getInputSpecification();
             if (isset($spec['required']) && $spec['required']) {
                 $replaces['{{label_class}}'] .= ' required';
                 $element->setAttribute('required', 'required');
             }
         }
         if ($errorMessages = $this->errorHelper->render($element)) {
             $replaces['{{error_messages}}'] = sprintf('<div class="error-messages">%s</div>', $errorMessages);
         }
         if ($replaces['{{error_messages}}']) {
             $replaces['{{row_class}}'] .= ' has-error';
         }
         if ($feedback = $element->getOption('feedback')) {
             $replaces['{{feedback}}'] = sprintf('<span class="fa fa-%s form-control-feedback"></span>', $feedback);
             $replaces['{{row_class}}'] .= ' has-feedback';
         }
         if ($helpText = $element->getOption('help')) {
             $replaces['{{help_text}}'] = sprintf('<div class="help-text help-block">%s</div>', $helpText);
         }
         if ($before = $element->getOption('before')) {
             $replaces['{{before}}'] = $before;
         }
         if ($after = $element->getOption('after')) {
             $replaces['{{after}}'] = $after;
         }
         if (!$element->getAttribute('id')) {
             $element->setAttribute('id', sprintf('input-id-%s', crc32(self::$suffix++)));
         }
         $replaces['{{elem_id}}'] = $element->getAttribute('id');
         $replaces['{{elem_markup}}'] = $this->elementHelper->render($element);
         return strtr($this->template, $replaces);
     }
 }
Ejemplo n.º 5
0
 /**
  * {@inheritDoc}
  *
  * @return FormElementErrors
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $serviceLocator = $serviceLocator->getServiceLocator();
     $helper = new FormElementErrors();
     $config = $serviceLocator->get('Config');
     if (isset($config['view_helper_config']['formelementerrors'])) {
         $configHelper = $config['view_helper_config']['formelementerrors'];
         if (isset($configHelper['message_open_format'])) {
             $helper->setMessageOpenFormat($configHelper['message_open_format']);
         }
         if (isset($configHelper['message_separator_string'])) {
             $helper->setMessageSeparatorString($configHelper['message_separator_string']);
         }
         if (isset($configHelper['message_close_string'])) {
             $helper->setMessageCloseString($configHelper['message_close_string']);
         }
     }
     return $helper;
 }
 /**
  * Render validation errors for the provided $oElement
  * @see \Zend\Form\View\Helper\FormElementErrors::render()
  * @param \Zend\Form\ElementInterface $oElement
  * @param array $aAttributes
  * @return string
  */
 public function render(\Zend\Form\ElementInterface $oElement, array $aAttributes = array())
 {
     if (isset($aAttributes['class'])) {
         if (!preg_match('/(\\s|^)advice(\\s|$)/', $aAttributes['class'])) {
             $aAttributes['class'] .= ' advice';
         }
     } else {
         $aAttributes['class'] = 'advice';
     }
     return parent::render($oElement, $aAttributes);
 }
Ejemplo n.º 7
0
 /**
  * Retrieve the FormElementErrors helper
  *
  * @return FormElementErrors
  */
 protected function getElementErrorsHelper()
 {
     if ($this->elementErrorsHelper) {
         return $this->elementErrorsHelper;
     }
     if (method_exists($this->view, 'plugin')) {
         $this->elementErrorsHelper = $this->view->plugin('form_element_errors');
     }
     if (!$this->elementErrorsHelper instanceof FormElementErrors) {
         $this->elementErrorsHelper = new FormElementErrors();
     }
     if ($this->hasTranslator()) {
         $this->elementErrorsHelper->setTranslator($this->getTranslator(), $this->getTranslatorTextDomain());
     }
     return $this->elementErrorsHelper;
 }
Ejemplo n.º 8
0
 /**
  * Get View Helper Configuration
  *
  * @return array
  */
 public function getViewHelperConfig()
 {
     return array('factories' => array('formElementErrors' => function ($sm) {
         $fee = new FormElementErrors();
         $fee->setMessageCloseString('</li></ul>');
         $fee->setMessageOpenFormat('<ul%s><li>');
         $fee->setMessageSeparatorString('</li><li>');
         $fee->setAttributes(array('class' => 'help-inline'));
         return $fee;
     }));
 }
Ejemplo n.º 9
0
 /**
  * {@inheritDoc}
  */
 public function render(ElementInterface $element, array $attributes = [])
 {
     $markup = '';
     $renderer = $this->getView();
     if (!method_exists($renderer, 'plugin')) {
         return $markup;
     }
     /* @var $flashMessenger \Zend\View\Helper\FlashMessenger */
     $flashMessenger = $renderer->plugin('flashmessenger');
     if ($flashMessenger->hasCurrentMessages() || $element->getMessages()) {
         $formName = $element->getName();
         foreach ($this->classMessages as $namespace => $class) {
             $attribs = $attributes;
             if ($namespace === PluginFlashMessenger::NAMESPACE_ERROR) {
                 $flashMessenger->setTranslatorTextDomain($this->getTranslatorTextDomain());
                 if (!$this->getMessageOpenFormat()) {
                     $this->setMessageOpenFormat($flashMessenger->getMessageOpenFormat());
                 }
                 if (!$this->getMessageSeparatorString()) {
                     $this->setMessageSeparatorString($flashMessenger->getMessageSeparatorString());
                 }
                 if (!$this->getMessageCloseString()) {
                     $this->setMessageCloseString($flashMessenger->getMessageCloseString());
                 }
                 if ($flashMessenger->hasCurrentMessages() && ($messages = $flashMessenger->getCurrentMessagesFromNamespace("{$formName}-{$namespace}"))) {
                     $element->setMessages(array_merge($element->getMessages(), $messages));
                 }
                 if (isset($attribs['class'])) {
                     $attribs['class'] .= ' ' . $class;
                 } else {
                     $attribs['class'] = $class;
                 }
                 $markup .= parent::render($element, $attribs);
             } elseif ($flashMessenger->hasCurrentMessages()) {
                 if (isset($attribs['class'])) {
                     $class = array_merge((array) $attribs['class'], (array) $class);
                 }
                 $markup .= $flashMessenger->renderCurrent("{$formName}-{$namespace}", (array) $class);
             }
         }
     }
     return $markup;
 }
 /**
  * Render validation errors for the provided $element
  * @param  ElementInterface $element
  * @param array $attributes
  * @return string
  */
 public function render(ElementInterface $element, array $attributes = array())
 {
     $attributes = $this->genUtil->addWordsToArrayItem('errors', $attributes, 'class');
     return parent::render($element, $attributes);
 }
Ejemplo n.º 11
0
 /**
  * Set Element Error Helper.
  *
  * @param \Zend\Form\View\Helper\FormElementErrors $errorHelper
  *
  * @return self
  */
 public function setElementErrorHelper(FormElementErrors $errorHelper)
 {
     $errorHelper->setView($this->getView());
     $this->elementErrorHelper = $errorHelper;
     return $this;
 }
Ejemplo n.º 12
0
 /**
  * Errors
  *
  * @param ElementInterface|null $element
  * @param array $attributes
  * @return string|Helper\FormElementErrors
  */
 public function elementErrors(ElementInterface $element = null, array $attributes = [])
 {
     $helper = new Helper\FormElementErrors();
     return $helper->__invoke($element, $attributes);
 }