/**
  * 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);
 }
 /**
  * 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);
     }
     $this->formUtil->addIdAttributeIfMissing($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);
 }
 /**
  * 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 #6
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);
 }