/**
  * Render a form <input> text element from the provided $element,
  * @param  ElementInterface $element
  * @param  null|string $formType
  * @param  array $displayOptions
  * @return string
  */
 public function render(ElementInterface $element, $formType = null, array $displayOptions = array())
 {
     $formType = $this->formUtil->filterFormType($formType);
     $this->prepareElementBeforeRendering($element, $formType, $displayOptions);
     $html = parent::render($element);
     //Text prepend / append
     $escapeHelper = $this->getEscapeHtmlHelper();
     $escapeAttribHelper = $this->getEscapeHtmlAttrHelper();
     $prepAppClass = '';
     //Prepend icon (not possible on Search forms)
     if ($formType != FormUtil::FORM_TYPE_SEARCH && array_key_exists('prependIcon', $displayOptions)) {
         $prepAppClass = $this->genUtil->addWords('input-prepend', $prepAppClass);
         $html = sprintf('<span class="add-on"><i class="%s"></i></span>%s', $escapeAttribHelper($displayOptions['prependIcon']), $html);
     }
     //Prepend text
     if ($element->getOption('prependText')) {
         $prepAppClass = $this->genUtil->addWords('input-prepend', $prepAppClass);
         $html = '<span class="add-on">' . $escapeHelper($element->getOption('prependText')) . '</span>' . $html;
     }
     //Append icon (not possible on Search forms)
     if ($formType != FormUtil::FORM_TYPE_SEARCH && array_key_exists('appendIcon', $displayOptions)) {
         $prepAppClass = $this->genUtil->addWords('input-append', $prepAppClass);
         $html .= sprintf('<span class="add-on"><i class="%s"></i></span>', $escapeAttribHelper($displayOptions['appendIcon']));
     }
     //Append text
     if ($element->getOption('appendText')) {
         $prepAppClass = $this->genUtil->addWords('input-append', $prepAppClass);
         $html .= '<span class="add-on">' . $escapeHelper($element->getOption('appendText')) . '</span>';
     }
     if ($prepAppClass) {
         $html = '<div class="' . $prepAppClass . '">' . "\n{$html}\n" . '</div>';
     }
     return $html;
 }
 /**
  * Renders a form element label from an element
  * @param \Zend\Form\ElementInterface $element
  * @param array|null $displayOptions
  * @return string
  * @throws \Zend\Form\Exception\DomainException
  */
 public function render(ElementInterface $element, array $displayOptions = array())
 {
     $labelContent = $element->getLabel();
     if (empty($labelContent)) {
         throw new DomainException(sprintf('%s: No label set in the element.', __METHOD__));
     }
     //Translate
     if (null !== ($translator = $this->getTranslator())) {
         $labelContent = $translator->translate($labelContent, $this->getTranslatorTextDomain());
     }
     //Escape
     $escaperHtml = $this->getEscapeHtmlHelper();
     $labelContent = $escaperHtml($labelContent);
     //Label attributes
     $labelAttributes = $element->getLabelAttributes();
     if (empty($labelAttributes)) {
         $labelAttributes = array();
     }
     $labelAttributes = $this->genUtil->addWordsToArrayItem('control-label', $labelAttributes, 'class');
     if (array_key_exists('required', $displayOptions) && $displayOptions['required']) {
         $labelAttributes = $this->genUtil->addWordsToArrayItem('required', $labelAttributes, 'class');
     }
     if (!array_key_exists('id', $labelAttributes)) {
         $labelAttributes['id'] = 'label-' . $element->getName();
     }
     $element->setLabelAttributes($labelAttributes);
     $formLabelHelper = $this->formLabelHelper;
     return $formLabelHelper($element, $labelContent);
 }
 /**
  * Returns the fieldset opening tag and legend tag, if legend is defined
  * @param FieldsetInterface $fieldset
  * @param string|null $formType
  * @param array $displayOptions
  * @return string
  */
 public function openTag(FieldsetInterface $fieldset, $formType = null, array $displayOptions = array())
 {
     $formType = $this->formUtil->filterFormType($formType);
     $class = $fieldset->getAttribute('class');
     if (array_key_exists('class', $displayOptions)) {
         $class = $this->genUtil->addWords($displayOptions['class'], $class);
     }
     $escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper();
     $class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper);
     $fieldset->setAttribute('class', $class);
     if ($class) {
         $classAttrib = sprintf(' class="%s"', $class);
     } else {
         $classAttrib = '';
     }
     $html = sprintf('<fieldset%s>', $classAttrib);
     $legend = $fieldset->getOption('legend');
     if ($legend && (!array_key_exists('display_legend', $displayOptions) || $displayOptions['display_legend']) && ($formType == FormUtil::FORM_TYPE_HORIZONTAL || $formType == FormUtil::FORM_TYPE_VERTICAL)) {
         //Translate
         if (null !== ($translator = $this->getTranslator())) {
             $legend = $translator->translate($legend, $this->getTranslatorTextDomain());
         }
         //Escape
         $escapeHelper = $this->getEscapeHtmlHelper();
         $legend = $escapeHelper($legend);
         $html .= "<legend>{$legend}</legend>";
     }
     return $html;
 }
 public function testEscapeWords()
 {
     $escaper = new \Zend\View\Helper\EscapeHtmlAttr();
     $words = "   \n  mon&day  tues<da>y     wed\"nesday thu'rsday    fri\\day     ";
     $correct = 'mon&amp;day tues&lt;da&gt;y wed&quot;nesday thu&#x27;rsday fri&#x5C;day';
     $escaped = $this->genUtil->escapeWords($words, $escaper);
     $this->assertEquals($correct, $escaped);
 }
 /**
  * Render a form <input> element from the provided $element
  * @param  ElementInterface $element
  * @param null|string $formType
  * @param array $displayOptions
  * @return string
  */
 public function render(ElementInterface $element, $formType = null, array $displayOptions = array())
 {
     $labelAttributes = $this->twbLabelAttributes;
     if (array_key_exists('inline', $displayOptions) && $displayOptions['inline'] == true) {
         $labelAttributes = $this->genUtil->addWordsToArrayItem('inline', $labelAttributes, 'class');
     }
     $formMultiCheckboxHelper = $this->formMultiCheckboxHelper;
     $formMultiCheckboxHelper->setLabelAttributes($labelAttributes);
     return $formMultiCheckboxHelper($element);
 }
 /**
  * Prepares the element prior to rendering
  * @param \Zend\Form\ElementInterface $element
  * @param string $formType
  * @param array $displayOptions
  * @return void
  */
 protected function prepareElementBeforeRendering(ElementInterface $element, $formType, array $displayOptions)
 {
     $class = $element->getAttribute('class');
     $class = $this->genUtil->addWords('btn', $class);
     if (array_key_exists('class', $displayOptions)) {
         $class = $this->genUtil->addWords($displayOptions['class'], $class);
     }
     if ($element->getOption('primary') && $element->getOption('primary') == true) {
         $class = $this->genUtil->addWords('btn-primary', $class);
     }
     $class = $this->genUtil->escapeWords($class, $this->getEscapeHtmlAttrHelper());
     $element->setAttribute('class', $class);
 }
 /**
  * Prepares the element prior to rendering
  * @param \Zend\Form\ElementInterface $element
  * @param string $formType
  * @param array $displayOptions
  * @return void
  */
 protected function prepareElementBeforeRendering(ElementInterface $element, $formType, array $displayOptions)
 {
     if (array_key_exists('class', $displayOptions)) {
         $class = $element->getAttribute('class');
         $class = $this->genUtil->addWords($displayOptions['class'], $class);
         $escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper();
         $class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper);
         $element->setAttribute('class', $class);
     }
     if (array_key_exists('rows', $displayOptions)) {
         $element->setAttribute('rows', (int) $displayOptions['rows']);
     }
     $this->formUtil->addIdAttributeIfMissing($element);
 }
 /**
  * Render a form <select> element from the provided $element
  * @param  ElementInterface $element
  * @param null|string $formType
  * @param array $displayOptions
  * @return string
  */
 public function render(ElementInterface $element, $formType = null, array $displayOptions = array())
 {
     if (array_key_exists('class', $displayOptions)) {
         $class = $element->getAttribute('class');
         $class = $this->genUtil->addWords($displayOptions['class'], $class);
         $escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper();
         $class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper);
         $element->setAttribute('class', $class);
     }
     if (array_key_exists('size', $displayOptions)) {
         $element->setAttribute('size', (int) $displayOptions['size']);
     }
     $this->formUtil->addIdAttributeIfMissing($element);
     $html = parent::render($element);
     return $html;
 }
Exemple #9
0
 /**
  * Generate an opening form tag
  * @param  null|FormInterface $form
  * @param null|string $formType
  * @param array $displayOptions
  * @throws \DluTwBootstrap\Form\Exception\UnsupportedFormTypeException
  * @return string
  */
 public function openTag(FormInterface $form = null, $formType = null, $displayOptions = array())
 {
     $formType = $this->formUtil->filterFormType($formType);
     if (!array_key_exists($formType, $this->formTypeMap)) {
         throw new UnsupportedFormTypeException("Unsupported form type '{$formType}'.");
     }
     if ($form) {
         $class = $this->genUtil->addWords($this->formTypeMap[$formType], $form->getAttribute('class'));
         if (array_key_exists('class', $displayOptions)) {
             $class = $this->genUtil->addWords($displayOptions['class'], $class);
         }
         $escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper();
         $class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper);
         $form->setAttribute('class', $class);
     }
     return parent::openTag($form);
 }
 /**
  * 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);
 }