Example #1
0
 /**
  * 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;
 }
Example #2
0
 public function testAddWordsToNullText()
 {
     $newWords = null;
     $text = null;
     $combined = $this->genUtil->addWords($newWords, $text);
     $this->assertEquals('', $combined);
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Example #7
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);
 }