[Form] Renamed option 'primitive' to 'single_control'

This commit is contained in:
Bernhard Schussek 2012-04-27 10:16:56 +02:00
parent 167e64f799
commit d3bb4d085c
45 changed files with 113 additions and 111 deletions

View File

@ -370,7 +370,7 @@
themes. themes.
The "field_widget" and all references to it should be renamed to The "field_widget" and all references to it should be renamed to
"form_widget_primitive": "form_widget_single_control":
Before: Before:
@ -389,7 +389,7 @@
{% block url_widget %} {% block url_widget %}
{% spaceless %} {% spaceless %}
{% set type = type|default('url') %} {% set type = type|default('url') %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% endspaceless %} {% endspaceless %}
{% endblock url_widget %} {% endblock url_widget %}
``` ```
@ -397,7 +397,7 @@
All other "field_*" blocks and references to them should be renamed to All other "field_*" blocks and references to them should be renamed to
"form_*". If you previously defined both a "field_*" and a "form_*" "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 block, you can merge them into a single "form_*" block and check the new
Boolean variable "primitive": Boolean variable "single_control":
Before: Before:
@ -420,7 +420,7 @@
``` ```
{% block form_errors %} {% block form_errors %}
{% spaceless %} {% spaceless %}
{% if primitive %} {% if single_control %}
... field code ... ... field code ...
{% else %} {% else %}
... form code ... ... form code ...

View File

@ -2,29 +2,29 @@
{% block form_widget %} {% block form_widget %}
{% spaceless %} {% spaceless %}
{% if primitive %} {% if single_control %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% else %} {% else %}
{{ block('form_widget_complex') }} {{ block('form_widget_compound') }}
{% endif %} {% endif %}
{% endspaceless %} {% endspaceless %}
{% endblock form_widget %} {% endblock form_widget %}
{% block form_widget_primitive %} {% block form_widget_single_control %}
{% spaceless %} {% spaceless %}
{% set type = type|default('text') %} {% set type = type|default('text') %}
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/> <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
{% endspaceless %} {% endspaceless %}
{% endblock form_widget_primitive %} {% endblock form_widget_single_control %}
{% block form_widget_complex %} {% block form_widget_compound %}
{% spaceless %} {% spaceless %}
<div {{ block('widget_container_attributes') }}> <div {{ block('widget_container_attributes') }}>
{{ block('form_rows') }} {{ block('form_rows') }}
{{ form_rest(form) }} {{ form_rest(form) }}
</div> </div>
{% endspaceless %} {% endspaceless %}
{% endblock form_widget_complex %} {% endblock form_widget_compound %}
{% block collection_widget %} {% block collection_widget %}
{% spaceless %} {% spaceless %}
@ -112,7 +112,7 @@
{% block datetime_widget %} {% block datetime_widget %}
{% spaceless %} {% spaceless %}
{% if widget == 'single_text' %} {% if widget == 'single_text' %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% else %} {% else %}
<div {{ block('widget_container_attributes') }}> <div {{ block('widget_container_attributes') }}>
{{ form_errors(form.date) }} {{ form_errors(form.date) }}
@ -127,7 +127,7 @@
{% block date_widget %} {% block date_widget %}
{% spaceless %} {% spaceless %}
{% if widget == 'single_text' %} {% if widget == 'single_text' %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% else %} {% else %}
<div {{ block('widget_container_attributes') }}> <div {{ block('widget_container_attributes') }}>
{{ date_pattern|replace({ {{ date_pattern|replace({
@ -143,7 +143,7 @@
{% block time_widget %} {% block time_widget %}
{% spaceless %} {% spaceless %}
{% if widget == 'single_text' %} {% if widget == 'single_text' %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% else %} {% else %}
<div {{ block('widget_container_attributes') }}> <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 %} {{ 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 %} {% spaceless %}
{# type="number" doesn't work with floats #} {# type="number" doesn't work with floats #}
{% set type = type|default('text') %} {% set type = type|default('text') %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% endspaceless %} {% endspaceless %}
{% endblock number_widget %} {% endblock number_widget %}
{% block integer_widget %} {% block integer_widget %}
{% spaceless %} {% spaceless %}
{% set type = type|default('number') %} {% set type = type|default('number') %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% endspaceless %} {% endspaceless %}
{% endblock integer_widget %} {% endblock integer_widget %}
{% block money_widget %} {% block money_widget %}
{% spaceless %} {% spaceless %}
{{ money_pattern|replace({ '{{ widget }}': block('form_widget_primitive') })|raw }} {{ money_pattern|replace({ '{{ widget }}': block('form_widget_single_control') })|raw }}
{% endspaceless %} {% endspaceless %}
{% endblock money_widget %} {% endblock money_widget %}
{% block url_widget %} {% block url_widget %}
{% spaceless %} {% spaceless %}
{% set type = type|default('url') %} {% set type = type|default('url') %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% endspaceless %} {% endspaceless %}
{% endblock url_widget %} {% endblock url_widget %}
{% block search_widget %} {% block search_widget %}
{% spaceless %} {% spaceless %}
{% set type = type|default('search') %} {% set type = type|default('search') %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% endspaceless %} {% endspaceless %}
{% endblock search_widget %} {% endblock search_widget %}
{% block percent_widget %} {% block percent_widget %}
{% spaceless %} {% spaceless %}
{% set type = type|default('text') %} {% set type = type|default('text') %}
{{ block('form_widget_primitive') }} % {{ block('form_widget_single_control') }} %
{% endspaceless %} {% endspaceless %}
{% endblock percent_widget %} {% endblock percent_widget %}
{% block password_widget %} {% block password_widget %}
{% spaceless %} {% spaceless %}
{% set type = type|default('password') %} {% set type = type|default('password') %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% endspaceless %} {% endspaceless %}
{% endblock password_widget %} {% endblock password_widget %}
{% block hidden_widget %} {% block hidden_widget %}
{% spaceless %} {% spaceless %}
{% set type = type|default('hidden') %} {% set type = type|default('hidden') %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% endspaceless %} {% endspaceless %}
{% endblock hidden_widget %} {% endblock hidden_widget %}
{% block email_widget %} {% block email_widget %}
{% spaceless %} {% spaceless %}
{% set type = type|default('email') %} {% set type = type|default('email') %}
{{ block('form_widget_primitive') }} {{ block('form_widget_single_control') }}
{% endspaceless %} {% endspaceless %}
{% endblock email_widget %} {% endblock email_widget %}
@ -219,7 +219,7 @@
{% block form_label %} {% block form_label %}
{% spaceless %} {% spaceless %}
{% if primitive %} {% if single_control %}
{% set label_attr = label_attr|merge({'for': id}) %} {% set label_attr = label_attr|merge({'for': id}) %}
{% endif %} {% endif %}
{% if required %} {% if required %}
@ -241,9 +241,11 @@
{% spaceless %} {% spaceless %}
<div> <div>
{{ form_label(form, label|default(null)) }} {{ form_label(form, label|default(null)) }}
{# If the child is a form, the errors are rendered inside the container #} {#
{# see block form_rows #} If the child is a compound form, the errors are rendered inside
{% if primitive %} the container. See also block form_rows.
#}
{% if single_control %}
{{ form_errors(form) }} {{ form_errors(form) }}
{% endif %} {% endif %}
{{ form_widget(form) }} {{ form_widget(form) }}
@ -318,7 +320,7 @@
{% block generic_label %}{{ block('form_label') }}{% endblock %} {% block generic_label %}{{ block('form_label') }}{% endblock %}
{% block widget_choice_options %}{{ block('choice_widget_options') }}{% endblock %} {% block widget_choice_options %}{{ block('choice_widget_options') }}{% endblock %}
{% block field_widget %}{{ block('form_widget_primitive') }}{% endblock %} {% block field_widget %}{{ block('form_widget_single_control') }}{% endblock %}
{% block field_label %}{{ block('form_label') }}{% endblock %} {% block field_label %}{{ block('form_label') }}{% endblock %}
{% block field_row %}{{ block('form_row') }}{% endblock %} {% block field_row %}{{ block('form_row') }}{% endblock %}
{% block field_enctype %}{{ block('form_enctype') }}{% endblock %} {% block field_enctype %}{{ block('form_enctype') }}{% endblock %}

View File

@ -7,7 +7,7 @@
{{ form_label(form, label|default(null)) }} {{ form_label(form, label|default(null)) }}
</td> </td>
<td> <td>
{% if primitive %} {% if single_control %}
{{ form_errors(form) }} {{ form_errors(form) }}
{% endif %} {% endif %}
{{ form_widget(form) }} {{ form_widget(form) }}
@ -18,7 +18,7 @@
{% block form_errors %} {% block form_errors %}
{% spaceless %} {% spaceless %}
{% if primitive %} {% if single_control %}
{{ parent() }} {{ parent() }}
{% else %} {% else %}
{% if errors|length > 0 %} {% if errors|length > 0 %}
@ -42,11 +42,11 @@
{% endspaceless %} {% endspaceless %}
{% endblock hidden_row %} {% endblock hidden_row %}
{% block form_widget_complex %} {% block form_widget_compound %}
{% spaceless %} {% spaceless %}
<table {{ block('widget_container_attributes') }}> <table {{ block('widget_container_attributes') }}>
{{ block('form_rows') }} {{ block('form_rows') }}
{{ form_rest(form) }} {{ form_rest(form) }}
</table> </table>
{% endspaceless %} {% endspaceless %}
{% endblock form_widget_complex %} {% endblock form_widget_compound %}

View File

@ -1,6 +1,6 @@
{% block form_widget_primitive %} {% block form_widget_single_control %}
{% spaceless %} {% spaceless %}
{% set type = type|default('text') %} {% set type = type|default('text') %}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" /> <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
{% endspaceless %} {% endspaceless %}
{% endblock form_widget_primitive %} {% endblock form_widget_single_control %}

View File

@ -1,8 +1,8 @@
{% extends 'form_div_layout.html.twig' %} {% extends 'form_div_layout.html.twig' %}
{% block form_widget_primitive %} {% block form_widget_single_control %}
{% spaceless %} {% spaceless %}
{% set type = type|default('text') %} {% set type = type|default('text') %}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" /> <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
{% endspaceless %} {% endspaceless %}
{% endblock form_widget_primitive %} {% endblock form_widget_single_control %}

View File

@ -1,8 +1,8 @@
{% use 'form_div_layout.html.twig' %} {% use 'form_div_layout.html.twig' %}
{% block form_widget_primitive %} {% block form_widget_single_control %}
{% spaceless %} {% spaceless %}
{% set type = type|default('text') %} {% set type = type|default('text') %}
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" /> <input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
{% endspaceless %} {% endspaceless %}
{% endblock form_widget_primitive %} {% endblock form_widget_single_control %}

View File

@ -1,5 +1,5 @@
<?php if ($widget == 'single_text'): ?> <?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->renderBlock('form_widget_primitive'); ?> <?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
<?php else: ?> <?php else: ?>
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>> <div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
<?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array( <?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array(

View File

@ -1,5 +1,5 @@
<?php if ($widget == 'single_text'): ?> <?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->renderBlock('form_widget_primitive'); ?> <?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
<?php else: ?> <?php else: ?>
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>> <div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
<?php echo $view['form']->widget($form['date']).' '.$view['form']->widget($form['time']) ?> <?php echo $view['form']->widget($form['date']).' '.$view['form']->widget($form['time']) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive', array('type' => isset($type) ? $type : 'email')) ?> <?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : 'email')) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive') ?> <?php echo $view['form']->renderBlock('form_widget_single_control') ?>

View File

@ -1,3 +1,3 @@
<?php if ($required) { $label_attr['class'] = trim((isset($label_attr['class']) ? $label_attr['class'] : '').' required'); } ?> <?php if ($required) { $label_attr['class'] = trim((isset($label_attr['class']) ? $label_attr['class'] : '').' required'); } ?>
<?php if ($primitive) { $label_attr['for'] = $id; } ?> <?php if ($single_control) { $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> <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>

View File

@ -1,6 +1,6 @@
<div> <div>
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?> <?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
<?php if ($primitive): ?> <?php if ($single_control): ?>
<?php echo $view['form']->errors($form) ?> <?php echo $view['form']->errors($form) ?>
<?php endif ?> <?php endif ?>
<?php echo $view['form']->widget($form) ?> <?php echo $view['form']->widget($form) ?>

View File

@ -1,5 +1,5 @@
<?php if ($primitive): ?> <?php if ($single_control): ?>
<?php echo $view['form']->renderBlock('form_widget_primitive')?> <?php echo $view['form']->renderBlock('form_widget_single_control')?>
<?php else: ?> <?php else: ?>
<?php echo $view['form']->renderBlock('form_widget_complex')?> <?php echo $view['form']->renderBlock('form_widget_compound')?>
<?php endif ?> <?php endif ?>

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive', array('type' => isset($type) ? $type : "hidden")) ?> <?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "hidden")) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive', array('type' => isset($type) ? $type : "number")) ?> <?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "number")) ?>

View File

@ -1 +1 @@
<?php echo str_replace('{{ widget }}', $view['form']->renderBlock('form_widget_primitive'), $money_pattern) ?> <?php echo str_replace('{{ widget }}', $view['form']->renderBlock('form_widget_single_control'), $money_pattern) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive', array('type' => isset($type) ? $type : "text")) ?> <?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "text")) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive', array('type' => isset($type) ? $type : "password")) ?> <?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "password")) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive', array('type' => isset($type) ? $type : "text")) ?> % <?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "text")) ?> %

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive', array('type' => isset($type) ? $type : "search")) ?> <?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "search")) ?>

View File

@ -1,5 +1,5 @@
<?php if ($widget == 'single_text'): ?> <?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->renderBlock('form_widget_primitive'); ?> <?php echo $view['form']->renderBlock('form_widget_single_control'); ?>
<?php else: ?> <?php else: ?>
<div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>> <div <?php echo $view['form']->renderBlock('widget_container_attributes') ?>>
<?php <?php

View File

@ -1 +1 @@
<?php echo $view['form']->renderBlock('form_widget_primitive', array('type' => isset($type) ? $type : "url")) ?> <?php echo $view['form']->renderBlock('form_widget_single_control', array('type' => isset($type) ? $type : "url")) ?>

View File

@ -1,4 +1,4 @@
<?php if ($primitive): ?> <?php if ($single_control): ?>
<?php if ($errors): ?> <?php if ($errors): ?>
<ul> <ul>
<?php foreach ($errors as $error): ?> <?php foreach ($errors as $error): ?>

View File

@ -3,7 +3,7 @@
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?> <?php echo $view['form']->label($form, isset($label) ? $label : null) ?>
</td> </td>
<td> <td>
<?php if ($primitive): ?> <?php if ($single_control): ?>
<?php echo $view['form']->errors($form) ?> <?php echo $view['form']->errors($form) ?>
<?php endif ?> <?php endif ?>
<?php echo $view['form']->widget($form) ?> <?php echo $view['form']->widget($form) ?>

View File

@ -60,10 +60,10 @@ CHANGELOG
* deprecated FieldType and merged it into FormType * deprecated FieldType and merged it into FormType
* [BC BREAK] renamed theme blocks * [BC BREAK] renamed theme blocks
* "field_*" to "form_*" * "field_*" to "form_*"
* "field_widget" to "form_widget_primitive" * "field_widget" to "form_widget_single_control"
* "widget_choice_options" to "choice_widget_options" * "widget_choice_options" to "choice_widget_options"
* "generic_label" to "form_label" * "generic_label" to "form_label"
* added theme blocks "form_widget_complex", "choice_widget_expanded" and * added theme blocks "form_widget_compound", "choice_widget_expanded" and
"choice_widget_collapsed" to make theming more modular "choice_widget_collapsed" to make theming more modular
* ValidatorTypeGuesser now guesses "collection" for array type constraint * ValidatorTypeGuesser now guesses "collection" for array type constraint
* added method `guessPattern` to FormTypeGuesserInterface to guess which pattern to use in the HTML5 attribute "pattern" * added method `guessPattern` to FormTypeGuesserInterface to guess which pattern to use in the HTML5 attribute "pattern"

View File

@ -51,9 +51,9 @@ class CheckboxType extends AbstractType
}; };
return array( return array(
'value' => '1', 'value' => '1',
'empty_data' => $emptyData, 'empty_data' => $emptyData,
'primitive' => true, 'single_control' => true,
); );
} }

View File

@ -165,7 +165,7 @@ class ChoiceType extends AbstractType
return $options['required'] ? null : ''; return $options['required'] ? null : '';
}; };
$primitive = function (Options $options) { $singleControl = function (Options $options) {
return !$options['expanded']; return !$options['expanded'];
}; };
@ -178,7 +178,7 @@ class ChoiceType extends AbstractType
'empty_data' => $emptyData, 'empty_data' => $emptyData,
'empty_value' => $emptyValue, 'empty_value' => $emptyValue,
'error_bubbling' => false, 'error_bubbling' => false,
'primitive' => $primitive, 'single_control' => $singleControl,
); );
} }

View File

@ -131,7 +131,7 @@ class DateTimeType extends AbstractType
*/ */
public function getDefaultOptions() public function getDefaultOptions()
{ {
$primitive = function (Options $options) { $singleControl = function (Options $options) {
return $options['widget'] === 'single_text'; return $options['widget'] === 'single_text';
}; };
@ -163,7 +163,7 @@ class DateTimeType extends AbstractType
// representation is not \DateTime, but an array, we need to unset // representation is not \DateTime, but an array, we need to unset
// this option. // this option.
'data_class' => null, 'data_class' => null,
'primitive' => $primitive, 'single_control' => $singleControl,
); );
} }

View File

@ -163,7 +163,7 @@ class DateType extends AbstractType
*/ */
public function getDefaultOptions() public function getDefaultOptions()
{ {
$primitive = function (Options $options) { $singleControl = function (Options $options) {
return $options['widget'] === 'single_text'; return $options['widget'] === 'single_text';
}; };
@ -186,7 +186,7 @@ class DateType extends AbstractType
// representation is not \DateTime, but an array, we need to unset // representation is not \DateTime, but an array, we need to unset
// this option. // this option.
'data_class' => null, 'data_class' => null,
'primitive' => $primitive, 'single_control' => $singleControl,
); );
} }

View File

@ -44,7 +44,7 @@ class FileType extends AbstractType
public function getDefaultOptions() public function getDefaultOptions()
{ {
return array( return array(
'primitive' => true, 'single_control' => true,
); );
} }

View File

@ -67,7 +67,7 @@ class FormType extends AbstractType
->setAttribute('invalid_message_parameters', $options['invalid_message_parameters']) ->setAttribute('invalid_message_parameters', $options['invalid_message_parameters'])
->setAttribute('translation_domain', $options['translation_domain']) ->setAttribute('translation_domain', $options['translation_domain'])
->setAttribute('virtual', $options['virtual']) ->setAttribute('virtual', $options['virtual'])
->setAttribute('primitive', $options['primitive']) ->setAttribute('single_control', $options['single_control'])
->setData($options['data']) ->setData($options['data'])
->setDataMapper(new PropertyPathMapper($options['data_class'])) ->setDataMapper(new PropertyPathMapper($options['data_class']))
->addEventSubscriber(new ValidationListener()) ->addEventSubscriber(new ValidationListener())
@ -133,7 +133,7 @@ class FormType extends AbstractType
->set('multipart', false) ->set('multipart', false)
->set('attr', $form->getAttribute('attr')) ->set('attr', $form->getAttribute('attr'))
->set('label_attr', $form->getAttribute('label_attr')) ->set('label_attr', $form->getAttribute('label_attr'))
->set('primitive', $form->getAttribute('primitive')) ->set('single_control', $form->getAttribute('single_control'))
->set('types', $types) ->set('types', $types)
->set('translation_domain', $form->getAttribute('translation_domain')) ->set('translation_domain', $form->getAttribute('translation_domain'))
; ;
@ -211,7 +211,7 @@ class FormType extends AbstractType
'attr' => array(), 'attr' => array(),
'label_attr' => array(), 'label_attr' => array(),
'virtual' => false, 'virtual' => false,
'primitive' => false, 'single_control' => false,
'invalid_message' => 'This value is not valid.', 'invalid_message' => 'This value is not valid.',
'invalid_message_parameters' => array(), 'invalid_message_parameters' => array(),
'translation_domain' => 'messages', 'translation_domain' => 'messages',

View File

@ -25,7 +25,7 @@ class HiddenType extends AbstractType
'required' => false, 'required' => false,
// Pass errors to the parent // Pass errors to the parent
'error_bubbling' => true, 'error_bubbling' => true,
'primitive' => true, 'single_control' => true,
); );
} }

View File

@ -37,11 +37,11 @@ class IntegerType extends AbstractType
{ {
return array( return array(
// default precision is locale specific (usually around 3) // default precision is locale specific (usually around 3)
'precision' => null, 'precision' => null,
'grouping' => false, 'grouping' => false,
// Integer cast rounds towards 0, so do the same when displaying fractions // Integer cast rounds towards 0, so do the same when displaying fractions
'rounding_mode' => \NumberFormatter::ROUND_DOWN, 'rounding_mode' => \NumberFormatter::ROUND_DOWN,
'primitive' => true, 'single_control' => true,
); );
} }

View File

@ -51,11 +51,11 @@ class MoneyType extends AbstractType
public function getDefaultOptions() public function getDefaultOptions()
{ {
return array( return array(
'precision' => 2, 'precision' => 2,
'grouping' => false, 'grouping' => false,
'divisor' => 1, 'divisor' => 1,
'currency' => 'EUR', 'currency' => 'EUR',
'primitive' => true, 'single_control' => true,
); );
} }

View File

@ -36,10 +36,10 @@ class NumberType extends AbstractType
{ {
return array( return array(
// default precision is locale specific (usually around 3) // default precision is locale specific (usually around 3)
'precision' => null, 'precision' => null,
'grouping' => false, 'grouping' => false,
'rounding_mode' => \NumberFormatter::ROUND_HALFUP, 'rounding_mode' => \NumberFormatter::ROUND_HALFUP,
'primitive' => true, 'single_control' => true,
); );
} }

View File

@ -31,9 +31,9 @@ class PercentType extends AbstractType
public function getDefaultOptions() public function getDefaultOptions()
{ {
return array( return array(
'precision' => 0, 'precision' => 0,
'type' => 'fractional', 'type' => 'fractional',
'primitive' => true, 'single_control' => true,
); );
} }

View File

@ -33,7 +33,7 @@ class TextType extends AbstractType
public function getDefaultOptions() public function getDefaultOptions()
{ {
return array( return array(
'primitive' => true, 'single_control' => true,
); );
} }

View File

@ -137,7 +137,7 @@ class TimeType extends AbstractType
*/ */
public function getDefaultOptions() public function getDefaultOptions()
{ {
$primitive = function (Options $options) { $singleControl = function (Options $options) {
return $options['widget'] === 'single_text'; return $options['widget'] === 'single_text';
}; };
@ -160,7 +160,7 @@ class TimeType extends AbstractType
// representation is not \DateTime, but an array, we need to unset // representation is not \DateTime, but an array, we need to unset
// this option. // this option.
'data_class' => null, 'data_class' => null,
'primitive' => $primitive, 'single_control' => $singleControl,
); );
} }

View File

@ -63,7 +63,7 @@ class CsrfValidationListener implements EventSubscriberInterface
$form = $event->getForm(); $form = $event->getForm();
$data = $event->getData(); $data = $event->getData();
if ($form->isRoot() && !$form->getAttribute('primitive')) { if ($form->isRoot() && !$form->getAttribute('single_control')) {
if (!isset($data[$this->fieldName]) || !$this->csrfProvider->isCsrfTokenValid($this->intention, $data[$this->fieldName])) { 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')); $form->addError(new FormError('The CSRF token is invalid. Please try to resubmit the form'));
} }

View File

@ -64,7 +64,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
*/ */
public function buildViewBottomUp(FormView $view, FormInterface $form) public function buildViewBottomUp(FormView $view, FormInterface $form)
{ {
if (!$view->hasParent() && !$form->getAttribute('primitive') && $form->hasAttribute('csrf_field_name')) { if (!$view->hasParent() && !$form->getAttribute('single_control') && $form->hasAttribute('csrf_field_name')) {
$name = $form->getAttribute('csrf_field_name'); $name = $form->getAttribute('csrf_field_name');
$csrfProvider = $form->getAttribute('csrf_provider'); $csrfProvider = $form->getAttribute('csrf_provider');
$intention = $form->getAttribute('csrf_intention'); $intention = $form->getAttribute('csrf_intention');

View File

@ -56,26 +56,26 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)); ));
} }
public function testCsrfProtectionByDefaultIfRootAndNotPrimitive() public function testCsrfProtectionByDefaultIfRootAndNotSingleControl()
{ {
$view = $this->factory $view = $this->factory
->create('form', null, array( ->create('form', null, array(
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'primitive' => false, 'single_control' => false,
)) ))
->createView(); ->createView();
$this->assertTrue($view->hasChild('csrf')); $this->assertTrue($view->hasChild('csrf'));
} }
public function testNoCsrfProtectionByDefaultIfNotPrimitiveButNotRoot() public function testNoCsrfProtectionByDefaultIfNotSingleControlButNotRoot()
{ {
$view = $this->factory $view = $this->factory
->createNamedBuilder('form', 'root') ->createNamedBuilder('form', 'root')
->add($this->factory ->add($this->factory
->createNamedBuilder('form', 'form', null, array( ->createNamedBuilder('form', 'form', null, array(
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'primitive' => false, 'single_control' => false,
)) ))
) )
->getForm() ->getForm()
@ -85,12 +85,12 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
$this->assertFalse($view->hasChild('csrf')); $this->assertFalse($view->hasChild('csrf'));
} }
public function testNoCsrfProtectionByDefaultIfRootButPrimitive() public function testNoCsrfProtectionByDefaultIfRootButSingleControl()
{ {
$view = $this->factory $view = $this->factory
->create('form', null, array( ->create('form', null, array(
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'primitive' => true, 'single_control' => true,
)) ))
->createView(); ->createView();
@ -103,7 +103,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
->create('form', null, array( ->create('form', null, array(
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'csrf_protection' => false, 'csrf_protection' => false,
'primitive' => false, 'single_control' => false,
)) ))
->createView(); ->createView();
@ -122,7 +122,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'csrf_provider' => $this->csrfProvider, 'csrf_provider' => $this->csrfProvider,
'intention' => '%INTENTION%', 'intention' => '%INTENTION%',
'primitive' => false, 'single_control' => false,
)) ))
->createView(); ->createView();
@ -140,7 +140,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
/** /**
* @dataProvider provideBoolean * @dataProvider provideBoolean
*/ */
public function testValidateTokenOnBindIfRootAndNotPrimitive($valid) public function testValidateTokenOnBindIfRootAndNotSingleControl($valid)
{ {
$this->csrfProvider->expects($this->once()) $this->csrfProvider->expects($this->once())
->method('isCsrfTokenValid') ->method('isCsrfTokenValid')
@ -152,7 +152,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'csrf_provider' => $this->csrfProvider, 'csrf_provider' => $this->csrfProvider,
'intention' => '%INTENTION%', 'intention' => '%INTENTION%',
'primitive' => false, 'single_control' => false,
)); ));
$form->bind(array( $form->bind(array(
@ -167,7 +167,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
$this->assertSame($valid, $form->isValid()); $this->assertSame($valid, $form->isValid());
} }
public function testFailIfRootAndNotPrimitiveAndTokenMissing() public function testFailIfRootAndNotSingleControlAndTokenMissing()
{ {
$this->csrfProvider->expects($this->never()) $this->csrfProvider->expects($this->never())
->method('isCsrfTokenValid'); ->method('isCsrfTokenValid');
@ -177,7 +177,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'csrf_provider' => $this->csrfProvider, 'csrf_provider' => $this->csrfProvider,
'intention' => '%INTENTION%', 'intention' => '%INTENTION%',
'primitive' => false, 'single_control' => false,
)); ));
$form->bind(array( $form->bind(array(
@ -192,7 +192,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
$this->assertFalse($form->isValid()); $this->assertFalse($form->isValid());
} }
public function testDontValidateTokenIfNotPrimitiveButNoRoot() public function testDontValidateTokenIfNotSingleControlButNoRoot()
{ {
$this->csrfProvider->expects($this->never()) $this->csrfProvider->expects($this->never())
->method('isCsrfTokenValid'); ->method('isCsrfTokenValid');
@ -204,7 +204,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'csrf_provider' => $this->csrfProvider, 'csrf_provider' => $this->csrfProvider,
'intention' => '%INTENTION%', 'intention' => '%INTENTION%',
'primitive' => false, 'single_control' => false,
)) ))
) )
->getForm() ->getForm()
@ -216,7 +216,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)); ));
} }
public function testDontValidateTokenIfRootButPrimitive() public function testDontValidateTokenIfRootButSingleControl()
{ {
$this->csrfProvider->expects($this->never()) $this->csrfProvider->expects($this->never())
->method('isCsrfTokenValid'); ->method('isCsrfTokenValid');
@ -226,7 +226,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
'csrf_field_name' => 'csrf', 'csrf_field_name' => 'csrf',
'csrf_provider' => $this->csrfProvider, 'csrf_provider' => $this->csrfProvider,
'intention' => '%INTENTION%', 'intention' => '%INTENTION%',
'primitive' => true, 'single_control' => true,
)); ));
$form->bind(array( $form->bind(array(