src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php
public function render(ElementInterface $oElement)
    {
        $oRenderer = $this->getView();
        if (!method_exists($oRenderer, 'plugin')) {
            return '';
        }

        $bShouldWrap = $this->shouldWrap;

        $sMarkup = '';
        $sElementLayout = $oElement->getOption('twb-layout');
        if ($oElement instanceof \IteratorAggregate) {
            $oElementHelper = $this->getElementHelper();
            $oFieldsetHelper = $this->getFieldsetHelper();

            foreach ($oElement->getIterator() as $oElementOrFieldset) {
                $aOptions = $oElementOrFieldset->getOptions();
                if ($sElementLayout && empty($aOptions['twb-layout'])) {
                    $aOptions['twb-layout'] = $sElementLayout;
                    $oElementOrFieldset->setOptions($aOptions);
                }

                if ($oElementOrFieldset instanceof \Zend\Form\FieldsetInterface) {
                    $sMarkup .= $oFieldsetHelper($oElementOrFieldset);
                } elseif ($oElementOrFieldset instanceof \Zend\Form\ElementInterface) {
                	if ($oElementOrFieldset->getOption('twb-row-open')) {
						$sMarkup .= '<div class="row">' . "\n";
					}

					$sMarkup .= $oElementHelper($oElementOrFieldset);

					if ($oElementOrFieldset->getOption('twb-row-close')) {
						$sMarkup .= '</div>' . "\n";
					}
                }
            }
            if ($oElement instanceof \Zend\Form\Element\Collection && $oElement->shouldCreateTemplate()) {
                $sMarkup .= $this->renderTemplate($oElement);
            }
        }

        if ($bShouldWrap) {
            if (false != ($sLabel = $oElement->getLabel())) {
                if (null !== ($oTranslator = $this->getTranslator())) {
                    $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain());
                }

                $sMarkup = sprintf(
                        static::$legendFormat, ($sAttributes = $this->createAttributesString($oElement->getLabelAttributes()? : array())) ? ' ' . $sAttributes : '', $this->getEscapeHtmlHelper()->__invoke($sLabel)
                ) . $sMarkup;
            }

            //Set form layout class
            if ($sElementLayout) {
                $sLayoutClass = 'form-' . $sElementLayout;
                if (false != ($sElementClass = $oElement->getAttribute('class'))) {
                    if (!preg_match('/(\s|^)' . preg_quote($sLayoutClass, '/') . '(\s|$)/', $sElementClass)) {
                        $oElement->setAttribute('class', trim($sElementClass . ' ' . $sLayoutClass));
                    }
                } else {
                    $oElement->setAttribute('class', $sLayoutClass);
                }
            }

            $sMarkup = sprintf(
                    static::$fieldsetFormat, ($sAttributes = $this->createAttributesString($oElement->getAttributes())) ? ' ' . $sAttributes : '', $sMarkup
            );
        }
        return $sMarkup;
    }
public function render(ElementInterface $oElement)
    {
        $oRenderer = $this->getView();
        if (!method_exists($oRenderer, 'plugin')) {
            return '';
        }

        $bShouldWrap = $this->shouldWrap;

        $sMarkup = '';
        $sElementLayout = $oElement->getOption('twb-layout');
        if ($oElement instanceof \IteratorAggregate) {
            $oElementHelper = $this->getElementHelper();
            $oFieldsetHelper = $this->getFieldsetHelper();

            foreach ($oElement->getIterator() as $oElementOrFieldset) {
                $aOptions = $oElementOrFieldset->getOptions();
                if ($sElementLayout && empty($aOptions['twb-layout'])) {
                    $aOptions['twb-layout'] = $sElementLayout;
                    $oElementOrFieldset->setOptions($aOptions);
                }

                if ($oElementOrFieldset instanceof \Zend\Form\FieldsetInterface) {
                    $sMarkup .= $oFieldsetHelper($oElementOrFieldset);
                } elseif ($oElementOrFieldset instanceof \Zend\Form\ElementInterface) {
                	if ($oElementOrFieldset->getOption('twb-row-open')) {
						$sMarkup .= '<div class="row">' . "\n";
					}

					$sMarkup .= $oElementHelper($oElementOrFieldset);

					if ($oElementOrFieldset->getOption('twb-row-close')) {
						$sMarkup .= '</div>' . "\n";
					}
                }
            }
            if ($oElement instanceof \Zend\Form\Element\Collection && $oElement->shouldCreateTemplate()) {
                $sMarkup .= $this->renderTemplate($oElement);
            }
        }

        if ($bShouldWrap) {
            if (false != ($sLabel = $oElement->getLabel())) {
                if (null !== ($oTranslator = $this->getTranslator())) {
                    $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain());
                }

                $sMarkup = sprintf(
                        static::$legendFormat, ($sAttributes = $this->createAttributesString($oElement->getLabelAttributes()? : array())) ? ' ' . $sAttributes : '', $this->getEscapeHtmlHelper()->__invoke($sLabel)
                ) . $sMarkup;
            }

            //Set form layout class
            if ($sElementLayout) {
                $sLayoutClass = 'form-' . $sElementLayout;
                if (false != ($sElementClass = $oElement->getAttribute('class'))) {
                    if (!preg_match('/(\s|^)' . preg_quote($sLayoutClass, '/') . '(\s|$)/', $sElementClass)) {
                        $oElement->setAttribute('class', trim($sElementClass . ' ' . $sLayoutClass));
                    }
                } else {
                    $oElement->setAttribute('class', $sLayoutClass);
                }
            }

            $sMarkup = sprintf(
                    static::$fieldsetFormat, ($sAttributes = $this->createAttributesString($oElement->getAttributes())) ? ' ' . $sAttributes : '', $sMarkup
            );
        }
        return $sMarkup;
    }
public function render ( ElementInterface $ oElement ) { $ oRenderer = $ this -> getView ( ) ; if ( ! method_exists ( $ oRenderer , 'plugin' ) ) { return '' ; } $ bShouldWrap = $ this -> shouldWrap ; $ sMarkup = '' ; $ sElementLayout = $ oElement -> getOption ( 'twb-layout' ) ; if ( $ oElement instanceof \ IteratorAggregate ) { $ oElementHelper = $ this -> getElementHelper ( ) ; $ oFieldsetHelper = $ this -> getFieldsetHelper ( ) ; foreach ( $ oElement -> getIterator ( ) as $ oElementOrFieldset ) { $ aOptions = $ oElementOrFieldset -> getOptions ( ) ; if ( $ sElementLayout && empty ( $ aOptions [ 'twb-layout' ] ) ) { $ aOptions [ 'twb-layout' ] = $ sElementLayout ; $ oElementOrFieldset -> setOptions ( $ aOptions ) ; } if ( $ oElementOrFieldset instanceof \ Zend \ Form \ FieldsetInterface ) { $ sMarkup .= $ oFieldsetHelper ( $ oElementOrFieldset ) ; } elseif ( $ oElementOrFieldset instanceof \ Zend \ Form \ ElementInterface ) { if ( $ oElementOrFieldset -> getOption ( 'twb-row-open' ) ) { $ sMarkup .= '<div class="row">' . "\n" ; } $ sMarkup .= $ oElementHelper ( $ oElementOrFieldset ) ; if ( $ oElementOrFieldset -> getOption ( 'twb-row-close' ) ) { $ sMarkup .= '</div>' . "\n" ; } } } if ( $ oElement instanceof \ Zend \ Form \ Element \ Collection && $ oElement -> shouldCreateTemplate ( ) ) { $ sMarkup .= $ this -> renderTemplate ( $ oElement ) ; } } if ( $ bShouldWrap ) { if ( false != ( $ sLabel = $ oElement -> getLabel ( ) ) ) { if ( null !== ( $ oTranslator = $ this -> getTranslator ( ) ) ) { $ sLabel = $ oTranslator -> translate ( $ sLabel , $ this -> getTranslatorTextDomain ( ) ) ; } $ sMarkup = sprintf ( static :: $ legendFormat , ( $ sAttributes = $ this -> createAttributesString ( $ oElement -> getLabelAttributes ( ) ? : array ( ) ) ) ? ' ' . $ sAttributes : '' , $ this -> getEscapeHtmlHelper ( ) -> __invoke ( $ sLabel ) ) . $ sMarkup ; } //Set form layout class
 if ( $ sElementLayout ) { $ sLayoutClass = 'form-' . $ sElementLayout ; if ( false != ( $ sElementClass = $ oElement -> getAttribute ( 'class' ) ) ) { if ( ! preg_match ( '/(\s|^)' . preg_quote ( $ sLayoutClass , '/' ) . '(\s|$)/' , $ sElementClass ) ) { $ oElement -> setAttribute ( 'class' , trim ( $ sElementClass . ' ' . $ sLayoutClass ) ) ; } } else { $ oElement -> setAttribute ( 'class' , $ sLayoutClass ) ; } } $ sMarkup = sprintf ( static :: $ fieldsetFormat , ( $ sAttributes = $ this -> createAttributesString ( $ oElement -> getAttributes ( ) ) ) ? ' ' . $ sAttributes : '' , $ sMarkup ) ; } return $ sMarkup ; }
Render a collection by iterating through all fieldsets and elements
@param \Zend\Form\ElementInterface $oElement
@return string
Render a collection by iterating through all fieldsets and elements