Skip to content


Subversion checkout URL

You can clone with
Download ZIP


@composedObject Form annotions doesn't allow for collections #5410

carnage opened this Issue · 0 comments

1 participant


There is currently no way to add a collection to a form via a composed object annotation; this means that for collections, you are forced to create a fieldset object to represent the collection manually and can't use annotations for this on their own.

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

        $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);

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

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

I've put this POC "patch" into Zend\Form\Annotation\ElementAnnotationListener which seems to generate the correct markup (and allows correct extraction of values) but obviously, this destroys the previous functionality. What would be the best way to turn this into a proper patch? The options to pass to the collection need to come from somewhere (composed object or composing object) and the composed object annotation either needs to take a new parameter (is_collection) or a new composedCollection (or a better name?) annotation needs to be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.