8000 [Form] Add new block_prefix option for an easy form theming by yceruto · Pull Request #29680 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Add new block_prefix option for an easy form theming #29680

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

Merged
merged 1 commit into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.3.0
-----

* added `block_prefix` option to `BaseType`.

4.2.0
-----

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/Extension/Core/Type/BaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) {
array_unshift($blockPrefixes, $type->getBlockPrefix());
}
if (null !== $options['block_prefix']) {
$blockPrefixes[] = $options['block_prefix'];
}
$blockPrefixes[] = $uniqueBlockPrefix;

$view->vars = array_replace($view->vars, array(
Expand Down Expand Up @@ -111,6 +114,7 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'block_name' => null,
'block_prefix' => null,
'disabled' => false,
'label' => null,
'label_format' => null,
Expand All @@ -119,6 +123,7 @@ public function configureOptions(OptionsResolver $resolver)
'auto_initialize' => true,
));

$resolver->setAllowedTypes('block_prefix', array('null', 'string'));
$resolver->setAllowedTypes('attr', 'array');
}
}
10000
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,16 @@ public function testSubmitNull($expected = null, $norm = null, $view = null)
{
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']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"attr",
"auto_initialize",
"block_name",
"block_prefix",
"by_reference",
"data",
"disabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
choice_translation_domain empty_data attr csrf_protection
choice_value error_bubbling auto_initialize csrf_token_id
choices trim block_name csrf_token_manager
expanded by_reference
group_by data
multiple disabled
placeholder help
preferred_choices help_attr
expanded block_prefix
group_by by_reference
multiple data
placeholder disabled
preferred_choices help
help_attr
Copy link
Contributor

Choose a reason for hiding this comment

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

hmpf this table rst layout makes it hard for small and readable diffs, because in this case only one string is changed (added)

inherit_data
label
label_attr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"attr",
"auto_initialize",
"block_name",
"block_prefix",
"by_reference",
"compound",
"data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Symfony\Component\Form\Extension\Core\Type\FormType (Block prefix: "form")
attr
auto_initialize
block_name
block_prefix
by_reference
compound
data
Expand Down
0