8000 [WIP][2.1][Form] Revert some BC breaks by vicb · Pull Request #4134 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP][2.1][Form] Revert some BC breaks #4134

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

Closed
wants to merge 8 commits into from
Closed
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
39 changes: 16 additions & 23 deletions UPGRADE-2.1.md
10000
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
```
* The custom factories for the firewall configuration are now
registered during the build method of bundles instead of being registered
by the end-user. This means that you will you need to remove the 'factories'
by the end-user. This means that you will you need to remove the 'factories'
keys in your security configuration.

* The Firewall listener is now registered after the Router listener. This
Expand Down Expand Up @@ -313,29 +313,29 @@
return isset($options['widget']) && 'single_text' === $options['widget'] ? 'text' : 'choice';
}
```

* The methods `getDefaultOptions()` and `getAllowedOptionValues()` of form
types no longer receive an option array.

You can specify options that depend on other options using closures instead.

Before:

```
public function getDefaultOptions(array $options)
{
$defaultOptions = array();

if ($options['multiple']) {
$defaultOptions['empty_data'] = array();
}

return $defaultOptions;
}
```

After:

```
public function getDefaultOptions()
{
Expand All @@ -346,7 +346,7 @@
);
}
```

The second argument `$previousValue` does not have to be specified if not
needed.

Expand All @@ -366,29 +366,22 @@
(or any other of the BIND events). In case you used the CallbackValidator
class, you should now pass the callback directly to `addEventListener`.

* simplified CSRF protection and removed the csrf type

* deprecated FieldType and merged it into FormType

* [BC BREAK] renamed "field_*" theme blocks to "form_*" and "field_widget" to
"input"

* The method `guessMinLength()` of FormTypeGuesserInterface was deprecated
and will be removed in Symfony 2.3. You should use the new method
`guessPattern()` instead which may return any regular expression that
is inserted in the HTML5 attribute "pattern".

Before:

public function guessMinLength($class, $property)
{
if (/* condition */) {
return new ValueGuess($minLength, Guess::LOW_CONFIDENCE);
}
}

After:

public function guessPattern($class, $property)
{
if (/* condition */) {
Expand Down Expand Up @@ -470,7 +463,7 @@
`validate` and its return value was dropped.

`ConstraintValidator` still contains the deprecated `isValid` method and
forwards `validate` calls to `isValid` by default. This BC layer will be
forwards `validate` calls to `isValid` by default. This BC layer will be
removed in Symfony 2.3. You are advised to rename your methods. You should
also remove the return values, which have never been used by the framework.

Expand Down Expand Up @@ -500,7 +493,7 @@
$this->context->addViolation($constraint->message, array(
'{{ value }}' => $value,
));

return;
}
}
Expand Down
137 changes: 50 additions & 87 deletions src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

{% block form_widget %}
{% spaceless %}
{% if form.children|length > 0 %}
<div {{ block('widget_container_attributes') }}>
{{ block('form_rows') }}
{{ form_rest(form) }}
</div>
{% else %}
{{ block('input') }}
{% endif %}
<div {{ block('widget_container_attributes') }}>
{{ block('field_rows') }}
{{ form_rest(form) }}
</div>
{% endspaceless %}
{% endblock form_widget %}

Expand Down Expand Up @@ -87,7 +83,7 @@
{% block datetime_widget %}
{% spaceless %}
{% if widget == 'single_text' %}
{{ block('input') }}
{{ block('field_widget') }}
{% else %}
<div {{ block('widget_container_attributes') }}>
{{ form_errors(form.date) }}
Expand All @@ -102,7 +98,7 @@
{% block date_widget %}
{% spaceless %}
{% if widget == 'single_text' %}
{{ block('input') }}
{{ block('field_widget') }}
{% else %}
<div {{ block('widget_container_attributes') }}>
{{ date_pattern|replace({
Expand All @@ -118,7 +114,7 @@
{% block time_widget %}
{% spaceless %}
{% if widget == 'single_text' %}
{{ block('input') }}
{{ block('field_widget') }}
{% 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 %}
Expand All @@ -131,60 +127,67 @@
{% spaceless %}
{# type="number" doesn't work with floats #}
{% set type = type|default('text') %}
{{ block('input') }}
{{ block('field_widget') }}
{% endspaceless %}
{% endblock number_widget %}

{% block integer_widget %}
{% spaceless %}
{% set type = type|default('number') %}
{{ block('input') }}
{{ block('field_widget') }}
{% endspaceless %}
{% endblock integer_widget %}

{% block money_widget %}
{% spaceless %}
{{ money_pattern|replace({ '{{ widget }}': block('input') })|raw }}
{{ money_pattern|replace({ '{{ widget }}': block('field_widget') })|raw }}
{% endspaceless %}
{% endblock money_widget %}

{% block url_widget %}
{% spaceless %}
{% set type = type|default('url') %}
{{ block('input') }}
{{ block('field_widget') }}
{% endspaceless %}
{% endblock url_widget %}

{% block search_widget %}
{% spaceless %}
{% set type = type|default('search') %}
{{ block('input') }}
{{ block('field_widget') }}
{% endspaceless %}
{% endblock search_widget %}

{% block percent_widget %}
{% spaceless %}
{% set type = type|default('text') %}
{{ block('input') }} %
{{ block('field_widget') }} %
{% endspaceless %}
{% endblock percent_widget %}

{% block field_widget %}
{% spaceless %}
{% set type = type|default('text') %}
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
{% endspaceless %}
{% endblock field_widget %}

{% block password_widget %}
{% spaceless %}
{% set type = type|default('password') %}
{{ block('input') }}
{{ block('field_widget') }}
{% endspaceless %}
{% endblock password_widget %}

{% block hidden_widget %}
{% set type = type|default('hidden') %}
{{ block('input') }}
{{ block('field_widget') }}
{% endblock hidden_widget %}

{% block email_widget %}
{% spaceless %}
{% set type = type|default('email') %}
{{ block('input') }}
{{ block('field_widget') }}
{% endspaceless %}
{% endblock email_widget %}

Expand All @@ -199,11 +202,15 @@
{% endspaceless %}
{% endblock %}

{% block field_label %}
{% spaceless %}
{% set attr = attr|merge({'for': id}) %}
{{ block('generic_label') }}
{% endspaceless %}
{% endblock field_label %}

{% block form_label %}
{% spaceless %}
{% if form.children|length == 0 %}
{% set attr = attr|merge({'for': id}) %}
{% endif %}
{{ block('generic_label') }}
{% endspaceless %}
{% endblock form_label %}
Expand All @@ -212,17 +219,24 @@

{% block repeated_row %}
{% spaceless %}
{{ block('form_rows') }}
{{ block('field_rows') }}
{% endspaceless %}
{% endblock repeated_row %}

{% block field_row %}
{% spaceless %}
<div>
{{ form_label(form, label|default(null)) }}
{{ form_errors(form) }}
{{ form_widget(form) }}
</div>
{% endspaceless %}
{% endblock field_row %}

{% block form_row %}
{% spaceless %}
<div>
{{ form_label(form, label|default(null)) }}
{% if form.children|length == 0 %}
{{ form_errors(form) }}
{% endif %}
{{ form_widget(form) }}
</div>
{% endspaceless %}
Expand All @@ -234,13 +248,13 @@

{# Misc #}

{% block form_enctype %}
{% block field_enctype %}
{% spaceless %}
{% if multipart %}enctype="multipart/form-data"{% endif %}
{% endspaceless %}
{% endblock form_enctype %}
{% endblock field_enctype %}

{% block form_errors %}
{% block field_errors %}
{% spaceless %}
{% if errors|length > 0 %}
<ul>
Expand All @@ -256,39 +270,32 @@
</ul>
{% endif %}
{% endspaceless %}
{% endblock form_errors %}
{% endblock field_errors %}

{% block form_rest %}
{% block field_rest %}
{% spaceless %}
{% for child in form %}
{% if not child.rendered %}
{{ form_row(child) }}
{% endif %}
{% endfor %}
{% endspaceless %}
{% endblock form_rest %}
{% endblock field_rest %}

{# Support #}

{% block form_rows %}
{% block field_rows %}
{% spaceless %}
{{ form_errors(form) }}
{% for child in form %}
{{ form_row(child) }}
{% endfor %}
{% endspaceless %}
{% endblock form_rows %}

{% block input %}
{% spaceless %}
{% set type = type|default('text') %}
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
{% endspaceless %}
{% endblock input %}
{% endblock field_rows %}

{% block widget_attributes %}
{% spaceless %}
id="{{ id }}" name="{{ full_name }}"{% if read_only %} readonly="readonly"{% endif %}{% if disabled %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
id="{{ id }}" name="{{ full_name }}"{% if read_only %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
{% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
{% endspaceless %}
{% endblock widget_attributes %}
Expand All @@ -299,47 +306,3 @@
{% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
{% endspaceless %}
{% endblock widget_container_attributes %}

{# Deprecated in Symfony 2.1, to be removed in 2.3 #}

{% block field_widget %}
{% spaceless %}
{{ block('input') }}
{% endspaceless %}
{% endblock field_widget %}

{% block field_label %}
{% spaceless %}
{{ block('form_label') }}
{% endspaceless %}
{% endblock field_label %}

{% block field_row %}
{% spaceless %}
{{ block('form_row') }}
{% endspaceless %}
{% endblock field_row %}

{% block field_enctype %}
{% spaceless %}
{{ block('form_enctype') }}
{% endspaceless %}
{% endblock field_enctype %}

{% block field_errors %}
{% spaceless %}
{{ block('form_errors') }}
{% endspaceless %}
{% endblock field_errors %}

{% block field_rest %}
{% spaceless %}
{{ block('form_rest') }}
{% endspaceless %}
{% endblock field_rest %}

{% block field_rows %}
{% spaceless %}
{{ block('form_rows') }}
{% endspaceless %}
{% endblock field_rows %}
Loading
0