Ejemplo n.º 1
0
 /**
  * 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;
 }