public function __invoke(FieldsetInterface $fieldset) { $fieldsetHelper = $this->getFieldsetHelper(); $name = preg_replace('/[^a-z0-9_-]+/', '', $fieldset->getName()); $result = '<div id="customFieldset' . $name . '">' . $fieldsetHelper($fieldset) . '</div>'; return $result; }
/** * {@inheritDoc} */ protected function prepareAndInjectObject($objectName, FieldsetInterface $fieldset, $method) { if (!is_string($objectName)) { throw new Exception\DomainException(sprintf('%s expects string class name; received "%s"', $method, is_object($objectName) ? get_class($objectName) : gettype($objectName))); } if (!class_exists($objectName)) { throw new Exception\DomainException(sprintf('%s expects string class name to be a valid class name; received "%s"', $method, $objectName)); } $om = null; if ($fieldset instanceof ObjectManagerAwareInterface) { $om = $fieldset->getObjectManager(); } if (!$om) { $om = $this->getObjectManager(); } $object = new $objectName(); if ($om) { /* @var $cm \Doctrine\Common\Persistence\Mapping\ClassMetadata */ if ($object instanceof ObjectManagerAware && $om->getMetadataFactory()->isTransient($objectName)) { $cm = $om->getClassMetadata($objectName); $object->injectObjectManager($om, $cm); } elseif ($object instanceof ObjectManagerAwareInterface) { $object->setObjectManager($om); } } $fieldset->setObject($object); }
public function __construct($formNameStr, $valueName, DoctrineHydrator $doctrineHydratorObj, FieldsetInterface $fieldsetObj) { parent::__construct($formNameStr); $this->setFormNameStr($formNameStr); $this->setHydrator($doctrineHydratorObj); $fieldsetObj->setUseAsBaseFieldset(true); $this->add($fieldsetObj); $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => $valueName))); }
public function render(FieldsetInterface $element) { $data = array('name' => $element->getName(), 'type' => 'fieldset', 'elements' => $this->renderElements($element)); $inputFilter = $element->getOption('inputFilter'); if ($inputFilter) { $inputData = $this->renderInputFilter($element, $inputFilter); foreach ($inputData as $name => $spec) { $original = empty($data['elements'][$name]) ? array() : $data['elements'][$name]; $data['elements'][$name] = array_merge($original, $spec); } } return $data; }
/** * Reflect css properties * * @param \Zend\Form\FieldsetInterface $fieldset * @param string $selector * @return \Zend\Form\FieldsetInterface */ protected function reflectCss(FieldsetInterface $fieldset, $selector) { foreach ($fieldset->getFieldsets() as $subFieldset) { if (!$subFieldset instanceof Collection) { $this->reflectCss($subFieldset, $selector); } } foreach ($fieldset->getElements() as $name => $element) { $types = array_filter(preg_split('/\\s+/', trim($element->getAttribute('data-js-type')))); $types[] = 'js.paragraph.reflectCss'; $element->setAttributes(array('data-js-type' => implode(' ', $types), 'data-js-reflectcss-selector' => $selector, 'data-js-reflectcss-property' => String::decamelize($name))); } return $fieldset; }
/** * * @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; }
/** * Iterate through all the elements and retrieve their validators * * @param FieldsetInterface $formOrFieldset * @param InputFilterInterface $inputFilter * @return array */ public function extractValidatorsForForm(FieldsetInterface $formOrFieldset, InputFilterInterface $inputFilter) { $foundValidators = array(); foreach ($formOrFieldset->getElements() as $element) { $validators = $this->getValidatorsForElement($inputFilter, $element); if (count($validators) > 0) { $foundValidators[] = array('element' => $element, 'validators' => $validators); } } foreach ($formOrFieldset->getFieldsets() as $key => $fieldset) { if ($inputFilter->has($key)) { $foundValidators = array_merge($foundValidators, $this->extractValidatorsForForm($fieldset, $inputFilter->get($key))); } } return $foundValidators; }
/** * Recursively extract values for elements and sub-fieldsets * * @return array */ protected function extract() { if (null !== $this->baseFieldset) { $name = $this->baseFieldset->getName(); $values[$name] = $this->baseFieldset->extract(); } else { $values = parent::extract(); } return $values; }
/** * @param $name * @return Element */ public function row($name) { if (isset($this->cache[$name])) { return $this->cache[$name]; } $elem = $this->fieldSet->get($name); if ($elem instanceof ZendFieldSet) { $return = new Element($elem, $this->renderer); $this->cache[$name] = $return; return $return; } throw new \DomainException('Invalid form fieldset object'); }
/** * Prepare and inject a named hydrator * * Takes a string indicating a hydrator class name (or a concrete instance), instantiates the class * by that name, and injects the hydrator instance into the form. * * @param string $hydratorOrName * @param FieldsetInterface $fieldset * @param string $method * @return void * @throws Exception\DomainException If $hydratorOrName is not a string, does not resolve to a known class, or * the class does not implement Hydrator\HydratorInterface */ protected function prepareAndInjectHydrator($hydratorOrName, FieldsetInterface $fieldset, $method) { if (is_object($hydratorOrName) && $hydratorOrName instanceof Hydrator\HydratorInterface) { $fieldset->setHydrator($hydratorOrName); return; } if (!is_string($hydratorOrName)) { throw new Exception\DomainException(sprintf('%s expects string hydrator class name; received "%s"', $method, is_object($hydratorOrName) ? get_class($hydratorOrName) : gettype($hydratorOrName))); } $sm = $this->getServiceManager(); if ($sm->has($hydratorOrName)) { $hydrator = $sm->get($hydratorOrName); } else { if (class_exists($hydratorOrName)) { $hydrator = new $hydratorOrName(); } else { throw new Exception\DomainException(sprintf('%s expects string hydrator name to be a valid class name or service; received "%s"', $method, $hydratorOrName)); } } if (!$hydrator instanceof Hydrator\HydratorInterface) { throw new Exception\DomainException(sprintf('%s expects a valid implementation of Zend\\Form\\Hydrator\\HydratorInterface; received "%s"', $method, $hydratorOrName)); } $fieldset->setHydrator($hydrator); }
/** * Extract values from the bound object and populate * the form elements * * @return void */ protected function extract() { if (!is_object($this->object)) { return; } $hydrator = $this->getHydrator(); if (!$hydrator instanceof Hydrator\HydratorInterface) { return; } $values = $hydrator->extract($this->object); if (!is_array($values)) { // Do nothing if the hydrator returned a non-array return; } if (null !== $this->baseFieldset) { $this->baseFieldset->populateValues($values); } else { $this->populateValues($values); } }
/** * 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'); }
/** * Attach defaults provided by the elements to the input filter * * @param InputFilterInterface $inputFilter * @param FieldsetInterface $fieldset Fieldset to traverse when looking for default inputs * @return void */ public function attachInputFilterDefaults(InputFilterInterface $inputFilter, FieldsetInterface $fieldset) { $formFactory = $this->getFormFactory(); $inputFactory = $formFactory->getInputFilterFactory(); foreach ($fieldset->getElements() as $element) { if (!$element instanceof InputProviderInterface) { // only interested in the element if it provides input information continue; } $name = $element->getName(); if ($inputFilter->has($name)) { // if we already have an input by this name, use it continue; } // Create an input based on the specification returned from the element $spec = $element->getInputSpecification(); $input = $inputFactory->createInput($spec); $inputFilter->add($input, $name); } foreach ($fieldset->getFieldsets() as $fieldset) { $name = $fieldset->getName(); if (!$fieldset instanceof InputFilterProviderInterface) { if (!$inputFilter->has($name)) { // Not an input filter provider, and no matching input for this fieldset. // Nothing more to do for this one. continue; } $fieldsetFilter = $inputFilter->get($name); if (!$fieldsetFilter instanceof InputFilterInterface) { // Input attached for fieldset, not input filter; nothing more to do. continue; } // Traverse the elements of the fieldset, and attach any // defaults to the fieldset's input filter $this->attachInputFilterDefaults($fieldsetFilter, $fieldset); continue; } if ($inputFilter->has($name)) { // if we already have an input/filter by this name, use it continue; } // Create an inputfilter based on the specification returned from the fieldset $spec = $fieldset->getInputFilterSpecification(); $filter = $inputFactory->createInputFilter($spec); $inputFilter->add($filter, $name); } }
/** * Takes a list of fieldset specifications, creates the fieldsets, and injects them into the master fieldset * * @param array|Traversable|ArrayAccess $fieldsets * @param FieldsetInterface $masterFieldset * @param string $method Method invoking this one (for exception messages) * @return void */ public function prepareAndInjectFieldsets($fieldsets, FieldsetInterface $masterFieldset, $method) { $fieldsets = $this->validateSpecification($fieldsets, $method); foreach ($fieldsets as $fieldsetSpecification) { $flags = isset($fieldsetSpecification['flags']) ? $fieldsetSpecification['flags'] : array(); $spec = isset($fieldsetSpecification['spec']) ? $fieldsetSpecification['spec'] : array(); $fieldset = $this->createFieldset($spec); $masterFieldset->add($fieldset, $flags); } }
/** * Prepare and inject a named hydrator * * Takes a string indicating a hydrator class name, instantiates the class * by that name, and injects the hydrator instance into the form. * * @param string $hydratorName * @param FieldsetInterface $fieldset * @param string $method * @return void * @throws Exception\DomainException if $hydratorName is not a string, does not resolve to a known class, or the class does not implement Hydrator\HydratorInterface */ protected function prepareAndInjectHydrator($hydratorName, FieldsetInterface $fieldset, $method) { if (!is_string($hydratorName)) { throw new Exception\DomainException(sprintf('%s expects string hydrator class name; received "%s"', $method, is_object($hydratorName) ? get_class($hydratorName) : gettype($hydratorName))); } if (!class_exists($hydratorName)) { throw new Exception\DomainException(sprintf('%s expects string hydrator name to be a valid class name; received "%s"', $method, $hydratorName)); } $hydrator = new $hydratorName(); if (!$hydrator instanceof Hydrator\HydratorInterface) { throw new Exception\DomainException(sprintf('%s expects a valid implementation of Zend\\Form\\Hydrator\\HydratorInterface; received "%s"', $method, $hydratorName)); } $fieldset->setHydrator($hydrator); }
/** * @inheritdoc */ public function getMessages() { return $this->element->getMessages(); }
/** * Renders the fieldset content * @param FieldsetInterface $fieldset * @param string|null $formType * @param array $displayOptions * @param bool $displayButtons * @param bool $renderErrors * @throws \DluTwBootstrap\Form\Exception\UnsupportedElementTypeException * @return string */ public function content(FieldsetInterface $fieldset, $formType = null, array $displayOptions = array(), $displayButtons = true, $renderErrors = true) { $renderer = $this->getView(); if (!method_exists($renderer, 'plugin')) { // Bail early if renderer is not pluggable return ''; } $formType = $this->formUtil->filterFormType($formType); $rowHelper = $renderer->plugin('form_row_twb'); $iterator = $fieldset->getIterator(); $html = ''; if (array_key_exists('fieldsets', $displayOptions)) { $displayOptionsFieldsets = $displayOptions['fieldsets']; } else { $displayOptionsFieldsets = array(); } if (array_key_exists('elements', $displayOptions)) { $displayOptionsElements = $displayOptions['elements']; } else { $displayOptionsElements = array(); } //Iterate over all fieldset elements and render them foreach ($iterator as $elementOrFieldset) { $elementName = $elementOrFieldset->getName(); $elementBareName = $this->formUtil->getBareElementName($elementName); if ($elementOrFieldset instanceof FieldsetInterface) { //Fieldset /* @var $elementOrFieldset FieldsetInterface */ //Get fieldset display options if (array_key_exists($elementBareName, $displayOptionsFieldsets)) { $displayOptionsFieldset = $displayOptionsFieldsets[$elementBareName]; } else { $displayOptionsFieldset = array(); } $html .= "\n" . $this->render($elementOrFieldset, $formType, $displayOptionsFieldset, true, true, $renderErrors); } elseif ($elementOrFieldset instanceof ElementInterface) { //Element /* @var $element ElementInterface */ if (!$displayButtons && in_array($elementOrFieldset->getAttribute('type'), array('submit', 'reset', 'button'))) { //We should ignore 'button' elements and this is a 'button' element, so skip the rest of the iteration continue; } //Get element display options if (array_key_exists($elementBareName, $displayOptionsElements)) { $displayOptionsElement = $displayOptionsElements[$elementBareName]; } else { $displayOptionsElement = array(); } $html .= "\n" . $rowHelper($elementOrFieldset, $formType, $displayOptionsElement, $renderErrors); } else { //Unsupported item type throw new UnsupportedElementTypeException('Fieldsets may contain only fieldsets or elements.'); } } return $html; }
/** * Prepare and inject a named hydrator * * Takes a string indicating a hydrator class name (or a concrete instance), try first to instantiates the class * by pulling it from service manager, and injects the hydrator instance into the form. * * @param string|array|Hydrator\HydratorInterface $hydratorOrName * @param FieldsetInterface $fieldset * @param string $method * @return void * @throws Exception\DomainException If $hydratorOrName is not a string, does not resolve to a known class, or * the class does not implement Hydrator\HydratorInterface */ protected function prepareAndInjectHydrator($hydratorOrName, FieldsetInterface $fieldset, $method) { if ($hydratorOrName instanceof Hydrator\HydratorInterface) { $fieldset->setHydrator($hydratorOrName); return; } if (is_array($hydratorOrName)) { if (!isset($hydratorOrName['type'])) { throw new Exception\DomainException(sprintf( '%s expects array specification to have a type value', $method )); } $hydratorOptions = (isset($hydratorOrName['options'])) ? $hydratorOrName['options'] : array(); $hydratorOrName = $hydratorOrName['type']; } else { $hydratorOptions = array(); } if (is_string($hydratorOrName)) { $hydrator = $this->getHydratorFromName($hydratorOrName); } if (!$hydrator instanceof Hydrator\HydratorInterface) { throw new Exception\DomainException(sprintf( '%s expects a valid implementation of Zend\Form\Hydrator\HydratorInterface; received "%s"', $method, $hydratorOrName )); } if (!empty($hydratorOptions) && $hydrator instanceof Hydrator\HydratorOptionsInterface) { $hydrator->setOptions($hydratorOptions); } $fieldset->setHydrator($hydrator); }
/** * {@inheritDoc} */ public function attachInputFilterDefaults(InputFilterInterface $inputFilter, FieldsetInterface $fieldset) { $inputFactory = $this->getFormFactory()->getInputFilterFactory(); if ($fieldset instanceof Collection && $fieldset->getTargetElement() instanceof FieldsetInterface) { $elements = $fieldset->getTargetElement()->getElements(); } else { $elements = $fieldset->getElements(); } if (!$fieldset instanceof Collection || !$fieldset->getTargetElement() instanceof FieldsetInterface || $inputFilter instanceof CollectionInputFilter) { foreach ($elements as $name => $element) { if ($element instanceof StaticElement) { if ($inputFilter->has($name)) { $inputFilter->remove($name); } continue; } if ($this->getPreferFormInputFilter() && !$this->mergeInputFilter() && $inputFilter->has($name)) { continue; } if (!$element instanceof InputProviderInterface) { if ($inputFilter->has($name)) { continue; } // Create a new empty default input for this element $input = $inputFactory->createInput(['name' => $name, 'required' => false]); } else { // Create an input based on the specification returned from the element $spec = $element->getInputSpecification(); $input = $inputFactory->createInput($spec); if ($inputFilter->has($name) && $inputFilter instanceof ReplaceableInputInterface) { $input->merge($inputFilter->get($name)); $inputFilter->replace($input, $name); continue; } } // Add element input filter to CollectionInputFilter if ($inputFilter instanceof CollectionInputFilter && !$inputFilter->getInputFilter()->has($name)) { $inputFilter->getInputFilter()->add($input, $name); } else { $inputFilter->add($input, $name); } } if ($fieldset === $this && $fieldset instanceof InputFilterProviderInterface) { foreach ($fieldset->getInputFilterSpecification() as $name => $spec) { $input = $inputFactory->createInput($spec); $inputFilter->add($input, $name); } } } foreach ($fieldset->getFieldsets() as $name => $childFieldset) { if (!$childFieldset instanceof InputFilterProviderInterface) { if (!$inputFilter->has($name)) { // Add a new empty input filter if it does not exist // (or the fieldset's object input filter), // so that elements of nested fieldsets can be recursively added if ($childFieldset->getObject() instanceof InputFilterAwareInterface) { $inputFilter->add($childFieldset->getObject()->getInputFilter(), $name); // Add input filter for collections via getInputFilterSpecification() } elseif ($childFieldset instanceof Collection && $childFieldset->getTargetElement() instanceof InputFilterProviderInterface && ($spec = $childFieldset->getTargetElement()->getInputFilterSpecification())) { $collectionContainerFilter = new CollectionInputFilter(); $filter = $inputFactory->createInputFilter($spec); // Add child elements from target element $childFieldset = $childFieldset->getTargetElement(); foreach ($childFieldset->getElements() as $element) { if ($element instanceof StaticElement) { $filter->remove($element->getName()); } } $collectionContainerFilter->setInputFilter($filter); $inputFilter->add($collectionContainerFilter, $name); // We need to copy the inputs to the collection input filter if ($inputFilter instanceof CollectionInputFilter) { $inputFilter = $this->addInputsToCollectionInputFilter($inputFilter); } } else { $inputFilter->add($inputFactory->createInputFilter([]), $name); } } $fieldsetFilter = $inputFilter->get($name); if (!$fieldsetFilter instanceof InputFilterInterface) { // Input attached for fieldset, not input filter; nothing more to do. continue; } if ($fieldsetFilter instanceof CollectionInputFilter) { $fieldsetFilter = $fieldsetFilter->getInputFilter(); } // Traverse the elements of the fieldset, and attach any // defaults to the fieldset's input filter $this->attachInputFilterDefaults($fieldsetFilter, $childFieldset); continue; } if (!$this->mergeInputFilter() && $inputFilter->has($name)) { // if we already have an input/filter by this name, use it continue; } // Create an input filter based on the specification returned from the fieldset $spec = $childFieldset->getInputFilterSpecification(); $filter = $inputFactory->createInputFilter($spec); if ($inputFilter->has($name)) { $filter = $inputFilter->get($name)->merge($filter); } else { $inputFilter->add($filter, $name); } // Recursively attach sub filters $this->attachInputFilterDefaults($filter, $childFieldset); // We need to copy the inputs to the collection input filter // to ensure that all sub filters are added if ($inputFilter instanceof CollectionInputFilter) { $inputFilter = $this->addInputsToCollectionInputFilter($inputFilter); } } }
/** * Iterate through all the elements and retrieve their validators * * @param FieldsetInterface $formOrFieldset * @param InputFilterInterface $inputFilter * @return array */ private function getElementAndRules(FieldsetInterface $formOrFieldset, InputFilterInterface $inputFilter) { $elements = array(); foreach ($formOrFieldset->getElements() as $element) { $validators = Filter::getValidatorsForElement($inputFilter, $element); if (count($validators) > 0 && !empty($element)) { $rules = array(); foreach ($validators as $validator) { $rule = $this->getServiceLocator()->get('Rule')->getRule($validator['instance']); if (!is_null($rule)) { $rules[] = $rule; } } $elements[] = array('element' => $element, 'rules' => $rules); } } foreach ($formOrFieldset->getFieldsets() as $key => $fieldset) { $elements = array_merge($elements, $this->getElementAndRules($fieldset, $inputFilter->get($key))); } return $elements; }
/** * @return null|string */ public function getPartial(FieldsetInterface $element = null) { $renderer = $this->getView(); if ($element && true === $this->partial && method_exists($renderer, 'resolver') && ($partial = $element->getOption('partial'))) { $class = new ReflectionClass($renderer); if ($class->hasMethod('getTemplate')) { $template = $renderer->getTemplate(); } elseif ($class->hasProperty('__template')) { $property = $class->getProperty('__template'); $property->setAccessible(true); $template = $property->getValue($renderer); } else { return; } if (is_string($partial) && is_string($template) && realpath($renderer->resolver($partial)) === realpath($renderer->resolver($template))) { return; } return $partial; } if (is_string($this->partial)) { return $this->partial; } }
/** * Attach defaults provided by the elements to the input filter * * @param InputFilterInterface $inputFilter * @param FieldsetInterface $fieldset Fieldset to traverse when looking for default inputs * @return void */ public function attachInputFilterDefaults(InputFilterInterface $inputFilter, FieldsetInterface $fieldset) { $formFactory = $this->getFormFactory(); $inputFactory = $formFactory->getInputFilterFactory(); //Fixed Zend bug: here will pass parent element to subform if ($this instanceof InputFilterProviderInterface && $this === $fieldset) { foreach ($this->getInputFilterSpecification() as $name => $spec) { $input = $inputFactory->createInput($spec); $inputFilter->add($input, $name); } } foreach ($fieldset->getElements() as $element) { $name = $element->getName(); if (!$element instanceof InputProviderInterface) { if ($inputFilter->has($name)) { continue; } // Create a new empty default input for this element $spec = array('name' => $name, 'required' => false); } else { // Create an input based on the specification returned from the element $spec = $element->getInputSpecification(); } $input = $inputFactory->createInput($spec); $inputFilter->add($input, $name); } foreach ($fieldset->getFieldsets() as $fieldset) { $name = $fieldset->getName(); if (!$fieldset instanceof InputFilterProviderInterface) { if (!$inputFilter->has($name)) { // Add a new empty input filter if it does not exist (or the fieldset's object input filter), // so that elements of nested fieldsets can be recursively added if ($fieldset->getObject() instanceof InputFilterAwareInterface) { $inputFilter->add($fieldset->getObject()->getInputFilter(), $name); } else { $inputFilter->add(new InputFilter(), $name); } } $fieldsetFilter = $inputFilter->get($name); if (!$fieldsetFilter instanceof InputFilterInterface) { // Input attached for fieldset, not input filter; nothing more to do. continue; } // Traverse the elements of the fieldset, and attach any // defaults to the fieldset's input filter $this->attachInputFilterDefaults($fieldsetFilter, $fieldset); continue; } if ($inputFilter->has($name)) { // if we already have an input/filter by this name, use it continue; } // Create an input filter based on the specification returned from the fieldset $spec = $fieldset->getInputFilterSpecification(); $filter = $inputFactory->createInputFilter($spec); $inputFilter->add($filter, $name); // Recursively attach sub filters $this->attachInputFilterDefaults($filter, $fieldset); } }
/** * Helper method. Retrieves all elements from fieldset the $element belongs to. * * @param ElementInterface $element * @param FieldsetInterface $fieldset * @return array|\Traversable */ protected function getFieldsetElements(ElementInterface $element, FieldsetInterface $fieldset) { $elementName = $this->normalizeElementName($element->getName()); if ($fieldset->has($elementName) && $fieldset->get($elementName) === $element) { return array_merge($fieldset->getElements(), $fieldset->getFieldsets()); } if ($fieldset instanceof Element\Collection && (($elements = $this->getFieldsetElements($element, $fieldset->getTargetElement())) || ($template = $fieldset->getTemplateElement()) && ($elements = $this->getFieldsetElements($element, $template)))) { return $elements; } foreach ($fieldset->getFieldsets() as $fieldsetElement) { if ($elements = $this->getFieldsetElements($element, $fieldsetElement)) { return $elements; } } return []; }
/** * Prepare and inject a named factory * * Takes a string indicating a factory class name (or a concrete instance), try first to instantiates the class * by pulling it from service manager, and injects the factory instance into the fieldset. * * @param string|array|Factory $factoryOrName * @param FieldsetInterface $fieldset * @param string $method * @return void * @throws Exception\DomainException If $factoryOrName is not a string, does not resolve to a known class, or * the class does not extend Form\Factory */ protected function prepareAndInjectFactory($factoryOrName, FieldsetInterface $fieldset, $method) { if (is_array($factoryOrName)) { if (!isset($factoryOrName['type'])) { throw new Exception\DomainException(sprintf('%s expects array specification to have a type value', $method)); } $factoryOrName = $factoryOrName['type']; } if (is_string($factoryOrName)) { $factoryOrName = $this->getFactoryFromName($factoryOrName); } if (!$factoryOrName instanceof Factory) { throw new Exception\DomainException(sprintf('%s expects a valid extention of Zend\\Form\\Factory; received "%s"', $method, $factoryOrName)); } $fieldset->setFormFactory($factoryOrName); }
/** * Render a fieldset * * @param \Zend\Form\FieldsetInterface $fieldset * @return string */ public function renderFieldset(FieldsetInterface $fieldset) { $legend = $fieldset->getLabel(); $attrs = $this->createFieldsetAttributes($fieldset); $markup = sprintf('<fieldset%s>', $attrs) . PHP_EOL; if ($legend && $this->isTranslatorEnabled()) { $legend = $this->getTranslator()->translate($legend, $this->getTranslatorTextDomain() ?: 'default'); } if ($legend) { $markup .= sprintf('<legend>%s</legend>', $legend); $markup .= PHP_EOL; } $markup .= $this->renderFieldsetContent($fieldset, 'fieldset'); $markup .= PHP_EOL; $markup .= '</fieldset>'; $markup .= PHP_EOL; return $markup; }