Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.3] [Form] New CollectionType prototype_data option #6910

Closed
wants to merge 1 commit into from
Closed

[2.3] [Form] New CollectionType prototype_data option #6910

wants to merge 1 commit into from

Conversation

adrienbrault
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #5095
License MIT
Doc PR symfony/symfony-docs#2192

Hey

@stof
Copy link
Member

stof commented Jan 29, 2013

you should provide a doc PR

@adrienbrault
Copy link
Contributor Author

I've created a PR on the documentation for this feature.

@adrienbrault
Copy link
Contributor Author

In case anyone can't wait for this feature to be merged (or is still using 2.1), here's a FormTypeExtension that provides the same feature https://gist.github.com/4666086 .

@vicb
Copy link
Contributor

vicb commented Jan 30, 2013

What about a more generic prototype-option ?

@stof
Copy link
Member

stof commented Jan 30, 2013

@vicb there is already options to pass option for all children. There is not a lot of options where it makes sense to distinguish the prototype or other children IMO (but the data is one as the prototype does not have mapped data)

@vicb
Copy link
Contributor

vicb commented Jan 30, 2013

Are nesting or user defined options some uc ? (note to myself: merge)

@gimler
Copy link
Contributor

gimler commented Feb 16, 2013

ping

@stof
Copy link
Member

stof commented Feb 16, 2013

@gimler this is a new feature, and 2.2 is in its RC cycle. So it would have to wait for 2.3. The priority currently is to stabilize 2.2, not to merge PRs for 2.3

'type' => 'form',
'allow_add' => true,
'prototype' => true,
'prototype_data' => $data = 'foobar',
Copy link
Contributor

Choose a reason for hiding this comment

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

imho, using a assignement here is confusing and not really needed

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @pborreli. Please change this to test directly against 'foobar' below.

@Bendihossan
Copy link

Does any more work need doing to this other than updating the test that @pborreli mentioned? It would be great to get this in 2.1 as well as 2.2 if possible.

@webmozart
Copy link
Contributor

ref #6350

@webmozart
Copy link
Contributor

ref #3825

@peterrehm
Copy link
Contributor

@bschussek Will this addition get into 2.3?

@mvrhov
Copy link

mvrhov commented May 19, 2013

No. 2.3 is in feature freeze.

@peterrehm
Copy link
Contributor

This I know, I just wanted to ping again to get the state. Its pending now for some time, hope that it will quickly get in.

@Venzon
Copy link

Venzon commented Jun 28, 2013

also looking for this feature
is there any way to set default values for prototype object?

@stof
Copy link
Member

stof commented Jun 28, 2013

@Venzon As said above, it is easy to do it usign a type extension waiting for it to be merged. See the gist linked by @adrienbrault

@Venzon
Copy link

Venzon commented Jun 28, 2013

@stof thanks a lot, I did not notice this gist

@Venzon
Copy link

Venzon commented Jul 3, 2013

@adrienbrault @stof
I did try to use CollectionTypeExtension (https://gist.github.com/4666086) by @adrienbrault but it does not work for me. Is my implementation somehow wrong? Defining prototype_data option inside TagType does not work aswell. Please help ^^

$builder->add('tags', 'collection', array(
    'type' => new TagType(),
    'allow_add' => true,
    'allow_delete' => true,
    'prototype_data' => function() {
        $object = new Tag();
        $object->setName('test')->setIsActive(true);
        return $object;
    },
));

Inside TagType class

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'Acme\TaskBundle\Entity\Tag',
        'prototype_data' => function() {
            $object = new Tag();
            $object->setName('test')->setIsActive(true);
            return $object;
        },
    ));
}

@webmozart
Copy link
Contributor

Closed in favor of #9177

@stof
Copy link
Member

stof commented Sep 30, 2013

@bschussek I'm not sure the related issue would allow fixing it: it should overwrite the data option only for the prototype, not for all children

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

Successfully merging this pull request may close these issues.

None yet

10 participants