merged branch IamPersistent/collection (PR #2416)
Commits -------fbd2a0e
make suggested changes for default valuec507b1d
update variable name to match the option nameb53f000
add the ability to set the form prototype name in CollectionType. this will aid in handling nested collections in forms Discussion ---------- [Form] Collection Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: [#1324](https://github.com/symfony/symfony/issues/1324) add the ability to set the form prototype name in CollectionType. this will aid in handling nested collections in forms --------------------------------------------------------------------------- by IamPersistent at 2011/10/17 02:54:45 -0700 Actually, as an afterthought, I looked over at the issues and this is basically https://github.com/symfony/symfony/issues/1324 just adding an extra option instead of using the prototype option. @stloyd, my thought was handling the case where someone was "clever" enough to set the 'prototype_name' option to "". But I could be over-thinking :) --------------------------------------------------------------------------- by stloyd at 2011/10/17 03:00:23 -0700 @IamPersistent IMO if someone is setting this option, he should be aware of that problem, also AFAIK `$$$$` could be *valid* name too ;-) --------------------------------------------------------------------------- by IamPersistent at 2011/10/17 03:02:14 -0700 @stloyd, I'm fine with changing it, I'll wait to see what everyone else has to say about this request vs using the prototype option for the name in 1324 --------------------------------------------------------------------------- by IamPersistent at 2011/10/17 03:28:49 -0700 @stloyd, @stof, I made the suggested changes, now I suppose, let the debate begin over PR1324 vs this --------------------------------------------------------------------------- by stloyd at 2011/10/17 03:47:53 -0700 IMO this PR makes changing prototype name in more clean way, so I would prefer this one over that proposed in #1324.
This commit is contained in:
commit
c18f5a8d94
@ -25,7 +25,7 @@ class CollectionType extends AbstractType
|
||||
public function buildForm(FormBuilder $builder, array $options)
|
||||
{
|
||||
if ($options['allow_add'] && $options['prototype']) {
|
||||
$prototype = $builder->create('$$name$$', $options['type'], $options['options']);
|
||||
$prototype = $builder->create('$$' . $options['prototype_name'] . '$$', $options['type'], $options['options']);
|
||||
$builder->setAttribute('prototype', $prototype->getForm());
|
||||
}
|
||||
|
||||
@ -75,11 +75,12 @@ class CollectionType extends AbstractType
|
||||
public function getDefaultOptions(array $options)
|
||||
{
|
||||
return array(
|
||||
'allow_add' => false,
|
||||
'allow_delete' => false,
|
||||
'prototype' => true,
|
||||
'type' => 'text',
|
||||
'options' => array(),
|
||||
'allow_add' => false,
|
||||
'allow_delete' => false,
|
||||
'prototype' => true,
|
||||
'prototype_name' => 'name',
|
||||
'type' => 'text',
|
||||
'options' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -166,4 +166,24 @@ class CollectionFormTest extends TypeTestCase
|
||||
$data = $form->getData();
|
||||
$this->assertFalse(isset($data['$$name$$']));
|
||||
}
|
||||
|
||||
public function testPrototypeNameOption()
|
||||
{
|
||||
$form = $this->factory->create('collection', null, array(
|
||||
'type' => 'field',
|
||||
'prototype' => true,
|
||||
'allow_add' => true,
|
||||
));
|
||||
|
||||
$this->assertSame('$$name$$', $form->getAttribute('prototype')->getName(), '$$name$$ is the default');
|
||||
|
||||
$form = $this->factory->create('collection', null, array(
|
||||
'type' => 'field',
|
||||
'prototype' => true,
|
||||
'allow_add' => true,
|
||||
'prototype_name' => 'test',
|
||||
));
|
||||
|
||||
$this->assertSame('$$test$$', $form->getAttribute('prototype')->getName());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user