Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Added ability to compose collections via Zend Form annotations #5420

Closed
wants to merge 2 commits into from

Conversation

carnage
Copy link
Contributor

@carnage carnage commented Nov 5, 2013

This patch resolves issue #5410

*/
public function getOptions()
{
return isset($this->value['options'])?$this->value['options']:array();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS -- wrap the operators (? and :) with spaces.

@carnage
Copy link
Contributor Author

carnage commented Nov 6, 2013

It's not visible from the diff, but the method already checks that further up

 public function handleComposedObjectAnnotation($e)
    {
        $annotation = $e->getParam('annotation');
        if (!$annotation instanceof ComposedObject) {
            return;
        }

        $class             = $annotation->getComposedObject();
        $annotationManager = $e->getTarget();
        $specification     = $annotationManager->getFormSpecification($class);

        $name        = $e->getParam('name');
        $elementSpec = $e->getParam('elementSpec');
        $filterSpec  = $e->getParam('filterSpec');

        // Compose input filter into parent input filter
        $inputFilter = $specification['input_filter'];
        if (!isset($inputFilter['type'])) {
            $inputFilter['type'] = 'Zend\InputFilter\InputFilter';
        }
        $e->setParam('inputSpec', $inputFilter);
        unset($specification['input_filter']);

        // Compose specification as a fieldset into parent form/fieldset
        if (!isset($specification['type'])) {
            $specification['type'] = 'Zend\Form\Fieldset';
        }
        if ($annotation->isCollection()) {
            $elementSpec['spec']['type'] = 'Zend\Form\Element\Collection';
            $elementSpec['spec']['name'] = $name;
            $elementSpec['spec']['options'] = new ArrayObject($annotation->getOptions());
            $elementSpec['spec']['options']['target_element'] = $specification;

            if (isset($specification['hydrator'])) {
                $elementSpec['spec']['hydrator'] = $specification['hydrator'];
            }
        } else {
            $elementSpec['spec'] = $specification;
            $elementSpec['spec']['name'] = $name;
        }
    }

The whole method for reference

weierophinney added a commit that referenced this pull request Nov 6, 2013
Added ability to compose collections via Zend Form annotations
weierophinney added a commit that referenced this pull request Nov 6, 2013
@ghost ghost assigned weierophinney Nov 6, 2013
@weierophinney
Copy link
Member

Merged to develop for release with 2.3.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants