/** * 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; }
/** * * @param \Zend\Form\FieldsetInterface $element * @return string */ public function render(FieldsetInterface $element) { $formCollection = $this->getRenderer()->plugin('formCollection'); $formCollection->setShouldWrap(false); $element->setAttribute('id', $element->getAttribute('name') . '-fieldset'); $attributeHelper = new Attributes(); $attributes = $attributeHelper->render($element, array('name')); $html = '<fieldset ' . $attributes . '>'; $label = $element->getLabel(); if ($label) { $html .= '<legend>' . $label . '</legend>'; } $html .= $formCollection->render($element); $html .= '</fieldset>'; return $html; }
/** * @inheritdoc */ public function setAttribute($key, $value) { return $this->element->setAttribute($key, $value); }
/** * Prepare the form element (mostly used for rendering purposes) * * @param FieldsetInterface $form * @return mixed */ public function prepareElement(FieldsetInterface $form) { // Ensure the form is using correct enctype $form->setAttribute('enctype', 'multipart/form-data'); }