Add block_prefix option for an easy form theming
This commit is contained in:
parent
32a53bfc13
commit
bd50ac44fc
@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
4.3.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* added `block_prefix` option to `BaseType`.
|
||||||
|
|
||||||
4.2.0
|
4.2.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -79,6 +79,9 @@ abstract class BaseType extends AbstractType
|
|||||||
for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) {
|
for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) {
|
||||||
array_unshift($blockPrefixes, $type->getBlockPrefix());
|
array_unshift($blockPrefixes, $type->getBlockPrefix());
|
||||||
}
|
}
|
||||||
|
if (null !== $options['block_prefix']) {
|
||||||
|
$blockPrefixes[] = $options['block_prefix'];
|
||||||
|
}
|
||||||
$blockPrefixes[] = $uniqueBlockPrefix;
|
$blockPrefixes[] = $uniqueBlockPrefix;
|
||||||
|
|
||||||
$view->vars = array_replace($view->vars, array(
|
$view->vars = array_replace($view->vars, array(
|
||||||
@ -111,6 +114,7 @@ abstract class BaseType extends AbstractType
|
|||||||
{
|
{
|
||||||
$resolver->setDefaults(array(
|
$resolver->setDefaults(array(
|
||||||
'block_name' => null,
|
'block_name' => null,
|
||||||
|
'block_prefix' => null,
|
||||||
'disabled' => false,
|
'disabled' => false,
|
||||||
'label' => null,
|
'label' => null,
|
||||||
'label_format' => null,
|
'label_format' => null,
|
||||||
@ -119,6 +123,7 @@ abstract class BaseType extends AbstractType
|
|||||||
'auto_initialize' => true,
|
'auto_initialize' => true,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$resolver->setAllowedTypes('block_prefix', array('null', 'string'));
|
||||||
$resolver->setAllowedTypes('attr', 'array');
|
$resolver->setAllowedTypes('attr', 'array');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -639,4 +639,16 @@ class FormTypeTest extends BaseTypeTest
|
|||||||
{
|
{
|
||||||
parent::testSubmitNull(array(), array(), array());
|
parent::testSubmitNull(array(), array(), array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPassBlockPrefixToViewWithParent()
|
||||||
|
{
|
||||||
|
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
|
||||||
|
->add('child', $this->getTestedType(), array(
|
||||||
|
'block_prefix' => 'child',
|
||||||
|
))
|
||||||
|
->getForm()
|
||||||
|
->createView();
|
||||||
|
|
||||||
|
$this->assertSame(array('form', 'child', '_parent_child'), $view['child']->vars['block_prefixes']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
"attr",
|
"attr",
|
||||||
"auto_initialize",
|
"auto_initialize",
|
||||||
"block_name",
|
"block_name",
|
||||||
|
"block_prefix",
|
||||||
"by_reference",
|
"by_reference",
|
||||||
"data",
|
"data",
|
||||||
"disabled",
|
"disabled",
|
||||||
|
@ -12,11 +12,12 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
|
|||||||
choice_translation_domain empty_data attr csrf_protection
|
choice_translation_domain empty_data attr csrf_protection
|
||||||
choice_value error_bubbling auto_initialize csrf_token_id
|
choice_value error_bubbling auto_initialize csrf_token_id
|
||||||
choices trim block_name csrf_token_manager
|
choices trim block_name csrf_token_manager
|
||||||
expanded by_reference
|
expanded block_prefix
|
||||||
group_by data
|
group_by by_reference
|
||||||
multiple disabled
|
multiple data
|
||||||
placeholder help
|
placeholder disabled
|
||||||
preferred_choices help_attr
|
preferred_choices help
|
||||||
|
help_attr
|
||||||
inherit_data
|
inherit_data
|
||||||
label
|
label
|
||||||
label_attr
|
label_attr
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"attr",
|
"attr",
|
||||||
"auto_initialize",
|
"auto_initialize",
|
||||||
"block_name",
|
"block_name",
|
||||||
|
"block_prefix",
|
||||||
"by_reference",
|
"by_reference",
|
||||||
"compound",
|
"compound",
|
||||||
"data",
|
"data",
|
||||||
|
@ -10,6 +10,7 @@ Symfony\Component\Form\Extension\Core\Type\FormType (Block prefix: "form")
|
|||||||
attr
|
attr
|
||||||
auto_initialize
|
auto_initialize
|
||||||
block_name
|
block_name
|
||||||
|
block_prefix
|
||||||
by_reference
|
by_reference
|
||||||
compound
|
compound
|
||||||
data
|
data
|
||||||
|
Reference in New Issue
Block a user