[Form] Inverted the logic of "single_control" and renamed it to "compound". The opposite is now "simple".
This commit is contained in:
parent
98a7c0cf5f
commit
2e6cdd15c5
@ -310,7 +310,7 @@
|
||||
themes.
|
||||
|
||||
The "field_widget" and all references to it should be renamed to
|
||||
"form_widget_single_control":
|
||||
"form_widget_simple":
|
||||
|
||||
Before:
|
||||
|
||||
@ -329,7 +329,7 @@
|
||||
{% block url_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('url') %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endspaceless %}
|
||||
{% endblock url_widget %}
|
||||
```
|
||||
@ -337,7 +337,7 @@
|
||||
All other "field_*" blocks and references to them should be renamed to
|
||||
"form_*". If you previously defined both a "field_*" and a "form_*"
|
||||
block, you can merge them into a single "form_*" block and check the new
|
||||
Boolean variable "single_control":
|
||||
Boolean variable "compound":
|
||||
|
||||
Before:
|
||||
|
||||
@ -360,10 +360,10 @@
|
||||
```
|
||||
{% block form_errors %}
|
||||
{% spaceless %}
|
||||
{% if single_control %}
|
||||
... field code ...
|
||||
{% else %}
|
||||
{% if compound %}
|
||||
... form code ...
|
||||
{% else %}
|
||||
... field code ...
|
||||
{% endif %}
|
||||
{% endspaceless %}
|
||||
{% endblock form_errors %}
|
||||
@ -487,7 +487,7 @@
|
||||
You can access all other methods on the `FormConfigInterface` object instead.
|
||||
|
||||
Instead of `getChildren` and `hasChildren`, you should now use `all` and
|
||||
`count` instead.
|
||||
`count`.
|
||||
|
||||
Before:
|
||||
|
||||
@ -609,7 +609,7 @@
|
||||
|
||||
* No options are passed to `getParent()` of `FormTypeInterface` anymore. If
|
||||
you previously dynamically inherited from FormType or FieldType, you can now
|
||||
dynamically set the "single_control" option instead.
|
||||
dynamically set the "compound" option instead.
|
||||
|
||||
Before:
|
||||
|
||||
@ -625,12 +625,12 @@
|
||||
```
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$singleControl = function (Options $options) {
|
||||
return !$options['expanded'];
|
||||
$compound = function (Options $options) {
|
||||
return $options['expanded'];
|
||||
};
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'single_control' => $singleControl,
|
||||
'compound' => $compound,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -2,20 +2,20 @@
|
||||
|
||||
{% block form_widget %}
|
||||
{% spaceless %}
|
||||
{% if single_control %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{% else %}
|
||||
{% if compound %}
|
||||
{{ block('form_widget_compound') }}
|
||||
{% else %}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endif %}
|
||||
{% endspaceless %}
|
||||
{% endblock form_widget %}
|
||||
|
||||
{% block form_widget_single_control %}
|
||||
{% block form_widget_simple %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
|
||||
{% endspaceless %}
|
||||
{% endblock form_widget_single_control %}
|
||||
{% endblock form_widget_simple %}
|
||||
|
||||
{% block form_widget_compound %}
|
||||
{% spaceless %}
|
||||
@ -112,7 +112,7 @@
|
||||
{% block datetime_widget %}
|
||||
{% spaceless %}
|
||||
{% if widget == 'single_text' %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% else %}
|
||||
<div {{ block('widget_container_attributes') }}>
|
||||
{{ form_errors(form.date) }}
|
||||
@ -127,7 +127,7 @@
|
||||
{% block date_widget %}
|
||||
{% spaceless %}
|
||||
{% if widget == 'single_text' %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% else %}
|
||||
<div {{ block('widget_container_attributes') }}>
|
||||
{{ date_pattern|replace({
|
||||
@ -143,7 +143,7 @@
|
||||
{% block time_widget %}
|
||||
{% spaceless %}
|
||||
{% if widget == 'single_text' %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% else %}
|
||||
<div {{ block('widget_container_attributes') }}>
|
||||
{{ form_widget(form.hour, { 'attr': { 'size': '1' } }) }}:{{ form_widget(form.minute, { 'attr': { 'size': '1' } }) }}{% if with_seconds %}:{{ form_widget(form.second, { 'attr': { 'size': '1' } }) }}{% endif %}
|
||||
@ -156,62 +156,62 @@
|
||||
{% spaceless %}
|
||||
{# type="number" doesn't work with floats #}
|
||||
{% set type = type|default('text') %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endspaceless %}
|
||||
{% endblock number_widget %}
|
||||
|
||||
{% block integer_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('number') %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endspaceless %}
|
||||
{% endblock integer_widget %}
|
||||
|
||||
{% block money_widget %}
|
||||
{% spaceless %}
|
||||
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_single_control') })|raw }}
|
||||
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
|
||||
{% endspaceless %}
|
||||
{% endblock money_widget %}
|
||||
|
||||
{% block url_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('url') %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endspaceless %}
|
||||
{% endblock url_widget %}
|
||||
|
||||
{% block search_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('search') %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endspaceless %}
|
||||
{% endblock search_widget %}
|
||||
|
||||
{% block percent_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
{{ block('form_widget_single_control') }} %
|
||||
{{ block('form_widget_simple') }} %
|
||||
{% endspaceless %}
|
||||
{% endblock percent_widget %}
|
||||
|
||||
{% block password_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('password') %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endspaceless %}
|
||||
{% endblock password_widget %}
|
||||
|
||||
{% block hidden_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('hidden') %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endspaceless %}
|
||||
{% endblock hidden_widget %}
|
||||
|
||||
{% block email_widget %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('email') %}
|
||||
{{ block('form_widget_single_control') }}
|
||||
{{ block('form_widget_simple') }}
|
||||
{% endspaceless %}
|
||||
{% endblock email_widget %}
|
||||
|
||||
@ -219,7 +219,7 @@
|
||||
|
||||
{% block form_label %}
|
||||
{% spaceless %}
|
||||
{% if single_control %}
|
||||
{% if not compound %}
|
||||
{% set label_attr = label_attr|merge({'for': id}) %}
|
||||
{% endif %}
|
||||
{% if required %}
|
||||
@ -245,7 +245,7 @@
|
||||
If the child is a compound form, the errors are rendered inside
|
||||
the container. See also block form_rows.
|
||||
#}
|
||||
{% if single_control %}
|
||||
{% if not compound %}
|
||||
{{ form_errors(form) }}
|
||||
{% endif %}
|
||||
{{ form_widget(form) }}
|
||||
@ -320,7 +320,7 @@
|
||||
|
||||
{% block generic_label %}{{ block('form_label') }}{% endblock %}
|
||||
{% block widget_choice_options %}{{ block('choice_widget_options') }}{% endblock %}
|
||||
{% block field_widget %}{{ block('form_widget_single_control') }}{% endblock %}
|
||||
{% block field_widget %}{{ block('form_widget_simple') }}{% endblock %}
|
||||
{% block field_label %}{{ block('form_label') }}{% endblock %}
|
||||
{% block field_row %}{{ block('form_row') }}{% endblock %}
|
||||
{% block field_enctype %}{{ block('form_enctype') }}{% endblock %}
|
||||
|
@ -7,7 +7,7 @@
|
||||
{{ form_label(form, label|default(null)) }}
|
||||
</td>
|
||||
<td>
|
||||
{% if single_control %}
|
||||
{% if not compound %}
|
||||
{{ form_errors(form) }}
|
||||
{% endif %}
|
||||
{{ form_widget(form) }}
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
{% block form_errors %}
|
||||
{% spaceless %}
|
||||
{% if single_control %}
|
||||
{% if not compound %}
|
||||
{{ parent() }}
|
||||
{% else %}
|
||||
{% if errors|length > 0 %}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{% block form_widget_single_control %}
|
||||
{% block form_widget_simple %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
|
||||
{% endspaceless %}
|
||||
{% endblock form_widget_single_control %}
|
||||
{% endblock form_widget_simple %}
|
||||
|
@ -1,8 +1,8 @@
|
||||
{% extends 'form_div_layout.html.twig' %}
|
||||
|
||||
{% block form_widget_single_control %}
|
||||
{% block form_widget_simple %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
|
||||
{% endspaceless %}
|
||||
{% endblock form_widget_single_control %}
|
||||
{% endblock form_widget_simple %}
|
||||
|
@ -1,8 +1,8 @@
|
||||
{% use 'form_div_layout.html.twig' %}
|
||||
|
||||
{% block form_widget_single_control %}
|
||||
{% block form_widget_simple %}
|
||||
{% spaceless %}
|
||||
{% set type = type|default('text') %}
|
||||
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
|
||||
{% endspaceless %}
|
||||
{% endblock form_widget_single_control %}
|
||||
{% endblock form_widget_simple %}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php if ($widget == 'single_text'): ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple'); ?>
|
||||
<?php else: ?>
|
||||
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
|
||||
<?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array(
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php if ($widget == 'single_text'): ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple'); ?>
|
||||
<?php else: ?>
|
||||
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
|
||||
<?php echo $view['form']->widget($form['date']).' '.$view['form']->widget($form['time']) ?>
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : 'email')) ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : 'email')) ?>
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control') ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple') ?>
|
||||
|
@ -1,3 +1,3 @@
|
||||
<?php if ($required) { $label_attr['class'] = trim((isset($label_attr['class']) ? $label_attr['class'] : '').' required'); } ?>
|
||||
<?php if ($single_control) { $label_attr['for'] = $id; } ?>
|
||||
<?php if (!$compound) { $label_attr['for'] = $id; } ?>
|
||||
<label <?php foreach ($label_attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>><?php echo $view->escape($view['translator']->trans($label, array(), $translation_domain)) ?></label>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div>
|
||||
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
|
||||
<?php if ($single_control): ?>
|
||||
<?php if (!$compound): ?>
|
||||
<?php echo $view['form']->errors($form) ?>
|
||||
<?php endif ?>
|
||||
<?php echo $view['form']->widget($form) ?>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php if ($single_control): ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control')?>
|
||||
<?php else: ?>
|
||||
<?php if ($compound): ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_compound')?>
|
||||
<?php else: ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple')?>
|
||||
<?php endif ?>
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "hidden")) ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "hidden")) ?>
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "number")) ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>
|
||||
|
@ -1 +1 @@
|
||||
<?php echo str_replace('{{ widget }}', $view['form']->renderBlock('form_widget_single_control'), $money_pattern) ?>
|
||||
<?php echo str_replace('{{ widget }}', $view['form']->renderBlock('form_widget_simple'), $money_pattern) ?>
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "text")) ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "text")) ?>
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "password")) ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "password")) ?>
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "text")) ?> %
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "text")) ?> %
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "search")) ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "search")) ?>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php if ($widget == 'single_text'): ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple'); ?>
|
||||
<?php else: ?>
|
||||
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
|
||||
<?php
|
||||
|
@ -1 +1 @@
|
||||
<?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "url")) ?>
|
||||
<?php echo $view['form']->renderBlock('form_widget_simple', array('type' => isset($type) ? $type : "url")) ?>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php if ($single_control): ?>
|
||||
<?php if (!$compound): ?>
|
||||
<?php if ($errors): ?>
|
||||
<ul>
|
||||
<?php foreach ($errors as $error): ?>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($single_control): ?>
|
||||
<?php if (!$compound): ?>
|
||||
<?php echo $view['form']->errors($form) ?>
|
||||
<?php endif ?>
|
||||
<?php echo $view['form']->widget($form) ?>
|
||||
|
@ -55,9 +55,10 @@ CHANGELOG
|
||||
by event subscribers
|
||||
* simplified CSRF protection and removed the csrf type
|
||||
* deprecated FieldType and merged it into FormType
|
||||
* added new option "compound" that lets you switch between field and form behavior
|
||||
* [BC BREAK] renamed theme blocks
|
||||
* "field_*" to "form_*"
|
||||
* "field_widget" to "form_widget_single_control"
|
||||
* "field_widget" to "form_widget_simple"
|
||||
* "widget_choice_options" to "choice_widget_options"
|
||||
* "generic_label" to "form_label"
|
||||
* added theme blocks "form_widget_compound", "choice_widget_expanded" and
|
||||
|
@ -51,9 +51,9 @@ class CheckboxType extends AbstractType
|
||||
};
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
'value' => '1',
|
||||
'empty_data' => $emptyData,
|
||||
'single_control' => true,
|
||||
'value' => '1',
|
||||
'empty_data' => $emptyData,
|
||||
'compound' => false,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -150,8 +150,8 @@ class ChoiceType extends AbstractType
|
||||
return $emptyValue;
|
||||
};
|
||||
|
||||
$singleControl = function (Options $options) {
|
||||
return !$options['expanded'];
|
||||
$compound = function (Options $options) {
|
||||
return $options['expanded'];
|
||||
};
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
@ -163,7 +163,7 @@ class ChoiceType extends AbstractType
|
||||
'empty_data' => $emptyData,
|
||||
'empty_value' => $emptyValue,
|
||||
'error_bubbling' => false,
|
||||
'single_control' => $singleControl,
|
||||
'compound' => $compound,
|
||||
));
|
||||
|
||||
$resolver->setFilters(array(
|
||||
|
@ -130,8 +130,8 @@ class DateTimeType extends AbstractType
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$singleControl = function (Options $options) {
|
||||
return $options['widget'] === 'single_text';
|
||||
$compound = function (Options $options) {
|
||||
return $options['widget'] !== 'single_text';
|
||||
};
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
@ -162,7 +162,7 @@ class DateTimeType extends AbstractType
|
||||
// representation is not \DateTime, but an array, we need to unset
|
||||
// this option.
|
||||
'data_class' => null,
|
||||
'single_control' => $singleControl,
|
||||
'compound' => $compound,
|
||||
));
|
||||
|
||||
$resolver->setAllowedValues(array(
|
||||
|
@ -165,8 +165,8 @@ class DateType extends AbstractType
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$singleControl = function (Options $options) {
|
||||
return $options['widget'] === 'single_text';
|
||||
$compound = function (Options $options) {
|
||||
return $options['widget'] !== 'single_text';
|
||||
};
|
||||
|
||||
$resolver->setDefaults(array(
|
||||
@ -188,7 +188,7 @@ class DateType extends AbstractType
|
||||
// representation is not \DateTime, but an array, we need to unset
|
||||
// this option.
|
||||
'data_class' => null,
|
||||
'single_control' => $singleControl,
|
||||
'compound' => $compound,
|
||||
));
|
||||
|
||||
$resolver->setAllowedValues(array(
|
||||
|
@ -45,7 +45,7 @@ class FileType extends AbstractType
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'single_control' => true,
|
||||
'compound' => false,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ class FormType extends AbstractType
|
||||
'multipart' => false,
|
||||
'attr' => $options['attr'],
|
||||
'label_attr' => $options['label_attr'],
|
||||
'single_control' => $options['single_control'],
|
||||
'compound' => $options['compound'],
|
||||
'types' => $types,
|
||||
'translation_domain' => $options['translation_domain'],
|
||||
));
|
||||
@ -170,7 +170,7 @@ class FormType extends AbstractType
|
||||
// For any form that is not represented by a single HTML control,
|
||||
// errors should bubble up by default
|
||||
$errorBubbling = function (Options $options) {
|
||||
return !$options['single_control'];
|
||||
return $options['compound'];
|
||||
};
|
||||
|
||||
// BC clause: former property_path=false now equals mapped=false
|
||||
@ -196,7 +196,7 @@ class FormType extends AbstractType
|
||||
'attr' => array(),
|
||||
'label_attr' => array(),
|
||||
'virtual' => false,
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
'translation_domain' => 'messages',
|
||||
));
|
||||
|
||||
|
@ -26,7 +26,7 @@ class HiddenType extends AbstractType
|
||||
'required' => false,
|
||||
// Pass errors to the parent
|
||||
'error_bubbling' => true,
|
||||
'single_control' => true,
|
||||
'compound' => false,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,11 @@ class IntegerType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
// default precision is locale specific (usually around 3)
|
||||
'precision' => null,
|
||||
'grouping' => false,
|
||||
'precision' => null,
|
||||
'grouping' => false,
|
||||
// Integer cast rounds towards 0, so do the same when displaying fractions
|
||||
'rounding_mode' => \NumberFormatter::ROUND_DOWN,
|
||||
'single_control' => true,
|
||||
'rounding_mode' => \NumberFormatter::ROUND_DOWN,
|
||||
'compound' => false,
|
||||
));
|
||||
|
||||
$resolver->setAllowedValues(array(
|
||||
|
@ -51,11 +51,11 @@ class MoneyType extends AbstractType
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'precision' => 2,
|
||||
'grouping' => false,
|
||||
'divisor' => 1,
|
||||
'currency' => 'EUR',
|
||||
'single_control' => true,
|
||||
'precision' => 2,
|
||||
'grouping' => false,
|
||||
'divisor' => 1,
|
||||
'currency' => 'EUR',
|
||||
'compound' => false,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -37,10 +37,10 @@ class NumberType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
// default precision is locale specific (usually around 3)
|
||||
'precision' => null,
|
||||
'grouping' => false,
|
||||
'rounding_mode' => \NumberFormatter::ROUND_HALFUP,
|
||||
'single_control' => true,
|
||||
'precision' => null,
|
||||
'grouping' => false,
|
||||
'rounding_mode' => \NumberFormatter::ROUND_HALFUP,
|
||||
'compound' => false,
|
||||
));
|
||||
|
||||
$resolver->setAllowedValues(array(
|
||||
|
@ -32,9 +32,9 @@ class PercentType extends AbstractType
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'precision' => 0,
|
||||
'type' => 'fractional',
|
||||
'single_control' => true,
|
||||
'precision' => 0,
|
||||
'type' => 'fractional',
|
||||
'compound' => false,
|
||||
));
|
||||
|
||||
$resolver->setAllowedValues(array(
|
||||
|
@ -34,7 +34,7 @@ class TextType extends AbstractType
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'single_control' => true,
|
||||
'compound' => false,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -130,8 +130,8 @@ class TimeType extends AbstractType
|
||||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$singleControl = function (Options $options) {
|
||||
return $options['widget'] === 'single_text';
|
||||
$compound = function (Options $options) {
|
||||
return $options['widget'] !== 'single_text';
|
||||
};
|
||||
|
||||
$emptyValueFilter = function (Options $options, $emptyValue) {
|
||||
@ -168,7 +168,7 @@ class TimeType extends AbstractType
|
||||
// representation is not \DateTime, but an array, we need to unset
|
||||
// this option.
|
||||
'data_class' => null,
|
||||
'single_control' => $singleControl,
|
||||
'compound' => $compound,
|
||||
));
|
||||
|
||||
$resolver->setFilters(array(
|
||||
|
@ -63,7 +63,7 @@ class CsrfValidationListener implements EventSubscriberInterface
|
||||
$form = $event->getForm();
|
||||
$data = $event->getData();
|
||||
|
||||
if ($form->isRoot() && !$form->getConfig()->getOption('single_control')) {
|
||||
if ($form->isRoot() && $form->getConfig()->getOption('compound')) {
|
||||
if (!isset($data[$this->fieldName]) || !$this->csrfProvider->isCsrfTokenValid($this->intention, $data[$this->fieldName])) {
|
||||
$form->addError(new FormError('The CSRF token is invalid. Please try to resubmit the form'));
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
||||
*/
|
||||
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
|
||||
{
|
||||
if ($options['csrf_protection'] && !$view->hasParent() && !$options['single_control']) {
|
||||
if ($options['csrf_protection'] && !$view->hasParent() && $options['compound']) {
|
||||
$factory = $form->getConfig()->getAttribute('csrf_factory');
|
||||
$data = $options['csrf_provider']->generateCsrfToken($options['intention']);
|
||||
|
||||
|
@ -529,19 +529,19 @@ class FormTypeTest extends TypeTestCase
|
||||
$this->assertFalse($view->isRendered());
|
||||
}
|
||||
|
||||
public function testErrorBubblingIfNoSingleControl()
|
||||
public function testErrorBubblingIfCompound()
|
||||
{
|
||||
$form = $this->factory->create('form', null, array(
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
));
|
||||
|
||||
$this->assertTrue($form->getErrorBubbling());
|
||||
}
|
||||
|
||||
public function testNoErrorBubblingIfSingleControl()
|
||||
public function testNoErrorBubblingIfNotCompound()
|
||||
{
|
||||
$form = $this->factory->create('form', null, array(
|
||||
'single_control' => true,
|
||||
'compound' => false,
|
||||
));
|
||||
|
||||
$this->assertFalse($form->getErrorBubbling());
|
||||
@ -550,7 +550,7 @@ class FormTypeTest extends TypeTestCase
|
||||
public function testOverrideErrorBubbling()
|
||||
{
|
||||
$form = $this->factory->create('form', null, array(
|
||||
'single_control' => true,
|
||||
'compound' => false,
|
||||
'error_bubbling' => true,
|
||||
));
|
||||
|
||||
|
@ -56,26 +56,26 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
));
|
||||
}
|
||||
|
||||
public function testCsrfProtectionByDefaultIfRootAndNotSingleControl()
|
||||
public function testCsrfProtectionByDefaultIfRootAndCompound()
|
||||
{
|
||||
$view = $this->factory
|
||||
->create('form', null, array(
|
||||
'csrf_field_name' => 'csrf',
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
))
|
||||
->createView();
|
||||
|
||||
$this->assertTrue($view->has('csrf'));
|
||||
}
|
||||
|
||||
public function testNoCsrfProtectionByDefaultIfNotSingleControlButNotRoot()
|
||||
public function testNoCsrfProtectionByDefaultIfCompoundButNotRoot()
|
||||
{
|
||||
$view = $this->factory
|
||||
->createNamedBuilder('root', 'form')
|
||||
->add($this->factory
|
||||
->createNamedBuilder('form', 'form', null, array(
|
||||
'csrf_field_name' => 'csrf',
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
))
|
||||
)
|
||||
->getForm()
|
||||
@ -85,12 +85,12 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
$this->assertFalse($view->has('csrf'));
|
||||
}
|
||||
|
||||
public function testNoCsrfProtectionByDefaultIfRootButSingleControl()
|
||||
public function testNoCsrfProtectionByDefaultIfRootButNotCompound()
|
||||
{
|
||||
$view = $this->factory
|
||||
->create('form', null, array(
|
||||
'csrf_field_name' => 'csrf',
|
||||
'single_control' => true,
|
||||
'compound' => false,
|
||||
))
|
||||
->createView();
|
||||
|
||||
@ -103,7 +103,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
->create('form', null, array(
|
||||
'csrf_field_name' => 'csrf',
|
||||
'csrf_protection' => false,
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
))
|
||||
->createView();
|
||||
|
||||
@ -122,7 +122,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
'csrf_field_name' => 'csrf',
|
||||
'csrf_provider' => $this->csrfProvider,
|
||||
'intention' => '%INTENTION%',
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
))
|
||||
->createView();
|
||||
|
||||
@ -140,7 +140,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
/**
|
||||
* @dataProvider provideBoolean
|
||||
*/
|
||||
public function testValidateTokenOnBindIfRootAndNotSingleControl($valid)
|
||||
public function testValidateTokenOnBindIfRootAndCompound($valid)
|
||||
{
|
||||
$this->csrfProvider->expects($this->once())
|
||||
->method('isCsrfTokenValid')
|
||||
@ -152,7 +152,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
'csrf_field_name' => 'csrf',
|
||||
'csrf_provider' => $this->csrfProvider,
|
||||
'intention' => '%INTENTION%',
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
));
|
||||
|
||||
$form->bind(array(
|
||||
@ -167,7 +167,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
$this->assertSame($valid, $form->isValid());
|
||||
}
|
||||
|
||||
public function testFailIfRootAndNotSingleControlAndTokenMissing()
|
||||
public function testFailIfRootAndCompoundAndTokenMissing()
|
||||
{
|
||||
$this->csrfProvider->expects($this->never())
|
||||
->method('isCsrfTokenValid');
|
||||
@ -177,7 +177,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
'csrf_field_name' => 'csrf',
|
||||
'csrf_provider' => $this->csrfProvider,
|
||||
'intention' => '%INTENTION%',
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
));
|
||||
|
||||
$form->bind(array(
|
||||
@ -192,7 +192,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
$this->assertFalse($form->isValid());
|
||||
}
|
||||
|
||||
public function testDontValidateTokenIfNotSingleControlButNoRoot()
|
||||
public function testDontValidateTokenIfCompoundButNoRoot()
|
||||
{
|
||||
$this->csrfProvider->expects($this->never())
|
||||
->method('isCsrfTokenValid');
|
||||
@ -204,7 +204,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
'csrf_field_name' => 'csrf',
|
||||
'csrf_provider' => $this->csrfProvider,
|
||||
'intention' => '%INTENTION%',
|
||||
'single_control' => false,
|
||||
'compound' => true,
|
||||
))
|
||||
)
|
||||
->getForm()
|
||||
@ -216,7 +216,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
));
|
||||
}
|
||||
|
||||
public function testDontValidateTokenIfRootButSingleControl()
|
||||
public function testDontValidateTokenIfRootButNotCompound()
|
||||
{
|
||||
$this->csrfProvider->expects($this->never())
|
||||
->method('isCsrfTokenValid');
|
||||
@ -226,7 +226,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
|
||||
'csrf_field_name' => 'csrf',
|
||||
'csrf_provider' => $this->csrfProvider,
|
||||
'intention' => '%INTENTION%',
|
||||
'single_control' => true,
|
||||
'compound' => false,
|
||||
));
|
||||
|
||||
$form->bind(array(
|
||||
|
Reference in New Issue
Block a user