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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 /**
  * 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);
     }
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function getName()
 {
     return $this->element->getName();
 }
Exemplo n.º 6
0
 /**
  * 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)) {
                 // Add a new empty input filter if it does not exist, so that elements of nested fieldsets can be
                 // recursively added
                 $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);
     }
 }
Exemplo n.º 7
0
    /**
     * 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);
        }
    }