8000 merged branch bschussek/issue3878 (PR #3923) · symfony/symfony@85bb439 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85bb439

Browse files
committed
merged branch bschussek/issue3878 (PR #3923)
Commits ------- 6e4ed9e [Form] Fixed regression: bind(null) was not converted to an empty string anymore fcb2227 [Form] Deprecated FieldType, which has been merged into FormType bfa7ef2 [Form] Removed obsolete exceptions 2a49449 [Form] Simplified CSRF mechanism and removed "csrf" type Discussion ---------- [Form] Merged FieldType into FormType Bug fix: no Feature addition: no Backwards compatibility break: yes Symfony2 tests pass: yes Fixes the following tickets: #3878 Todo: update the documentation on theming ![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue3878) This PR is a preparatory PR for #3879. See also #3878. --------------------------------------------------------------------------- by juliendidier at 2012-04-13T14:25:19Z What's the benefit ? --------------------------------------------------------------------------- by henrikbjorn at 2012-04-13T14:26:40Z why `input_widget` ? and not just `widget` --------------------------------------------------------------------------- by Burgov at 2012-04-13T14:27:49Z @juliendidier dynamic inheritance is now obsolete which fixes some other issues --------------------------------------------------------------------------- by stloyd at 2012-04-13T14:37:26Z What about __not__ breaking API so *badly* and leaving `FieldType` which will be simple like (with marking as deprecated): ```php <?php class FieldType extends AbstractType { public function getParent(array $options) { return 'form'; } public function getName() { return 'field'; } } --------------------------------------------------------------------------- by bschussek at 2012-04-13T14:43:41Z @stloyd That's a very good idea. --------------------------------------------------------------------------- by mvrhov at 2012-04-13T17:41:21Z IMHO what @stloyd proposed sounds like a good idea, but removing FieldType class, if #3903 will come into life might ensure that more forms will broke and people will check them thoroughly. --------------------------------------------------------------------------- by r1pp3rj4ck at 2012-04-13T18:46:08Z @bschussek looks great, but I'm concerned about how quickly will the third-party bundles adapt to this BC break. I hope really quick, because if they don't the whole stuff will be useless :S of course it's not your problem to solve. --------------------------------------------------------------------------- by stof at 2012-04-13T18:50:32Z @r1pp3rj4ck there is already another BC break requiring to update custom types for Symfony master. So third party bundles already have to do some work. --------------------------------------------------------------------------- by r1pp3rj4ck at 2012-04-13T18:59:37Z @stof which one? I've looked into @bschussek 's RFC about these [foo].bar stuff, but it's not yet implemented. Are you refering to this or another one I've missed? --------------------------------------------------------------------------- by stof at 2012-04-13T19:04:06Z @r1pp3rj4ck the change regarding default options --------------------------------------------------------------------------- by r1pp3rj4ck at 2012-04-13T19:06:10Z @stof oh, I forgot that one. Weird thing is that I've already changed my default options today and still forgetting these stuff :D --------------------------------------------------------------------------- by bschussek at 2012-04-14T08:58:29Z I restored and deprecated FieldType now. I'd appreciate further reviews. --------------------------------------------------------------------------- by stloyd at 2012-04-14T09:02:32Z Maybe we should try to avoid this BC in templates ? What do you think about similar move like with `FieldType` ? (hold old, but inside just render new) --------------------------------------------------------------------------- by bschussek at 2012-04-14T09:07:22Z @stloyd You mean for those cases where people explicitely render the block "field_*"? We can do that. --------------------------------------------------------------------------- by stloyd at 2012-04-14T09:09:45Z @bschussek Yes I mean this case =) Sorry for not being explicit, I need some coffee I think =) --------------------------------------------------------------------------- by bschussek at 2012-04-17T14:45:35Z I added the field_* blocks again for BC. Could someone please review again? Otherwise this can be merged. --------------------------------------------------------------------------- by Burgov at 2012-04-17T15:11:16Z @bschussek I'm not sure what has changed to cause this, but if I try out your branch on our forms, if I leave the value of an input empty, eventually the reverseTransform method receives a null value, rather than a '' (empty string) value, as on the current symfony master. DateTimeToLocalizedStringTransformer, for example, will throw an Exception if the value is not a string ```php if (!is_string($value)) { throw new UnexpectedTypeException($value, 'string'); } ``` Other than that, all forms render just the same as they do on symfony master --------------------------------------------------------------------------- by bschussek at 2012-04-17T15:30:29Z @Burgov Fixed.
2 parents 962f975 + 6e4ed9e commit 85bb439

File tree

91 files changed

+1304
-1472
lines changed
  • Bundle/FrameworkBundle
  • Component/Form
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    91 files changed

    +1304
    -1472
    lines changed

    CHANGELOG-2.1.md

    Lines changed: 5 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -267,8 +267,12 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
    267267
    in their name anymore. Their names terminate with "[]" now.
    268268
    * [BC BREAK] FormType::getDefaultOptions() and FormType::getAllowedOptionValues()
    269269
    don't receive an options array anymore.
    270-
    * Deprecated FormValidatorInterface and substituted its implementations
    270+
    * deprecated FormValidatorInterface and substituted its implementations
    271271
    by event subscribers
    272+
    * simplified CSRF protection and removed the csrf type
    273+
    * deprecated FieldType and merged it into FormType
    274+
    * [BC BREAK] renamed "field_*" theme blocks to "form_*" and "field_widget" to
    275+
    "input"
    272276

    273277
    ### HttpFoundation
    274278

    UPGRADE-2.1.md

    Lines changed: 7 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -358,6 +358,13 @@
    358358
    (or any other of the BIND events). In case you used the CallbackValidator
    359359
    class, you should now pass the callback directly to `addEventListener`.
    360360
    361+
    * simplified CSRF protection and removed the csrf type
    362+
    363+
    * deprecated FieldType and merged it into FormType
    364+
    365+
    * [BC BREAK] renamed "field_*" theme blocks to "form_*" and "field_widget" to
    366+
    "input"
    367+
    361368
    ### Validator
    362369
    363370
    * The methods `setMessage()`, `getMessageTemplate()` and

    src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

    Lines changed: 86 additions & 49 deletions
    Original file line numberDiff line numberDiff line change
    @@ -2,10 +2,14 @@
    22

    33
    {% block form_widget %}
    44
    {% spaceless %}
    5-
    <div {{ block('widget_container_attributes') }}>
    6-
    {{ block('field_rows') }}
    7-
    {{ form_rest(form) }}
    8-
    </div>
    5+
    {% if form.children|length > 0 %}
    6+
    <div {{ block('widget_container_attributes') }}>
    7+
    {{ block('form_rows') }}
    8+
    {{ form_rest(form) }}
    9+
    </div>
    10+
    {% else %}
    11+
    {{ block('input') }}
    12+
    {% endif %}
    913
    {% endspaceless %}
    1014
    {% endblock form_widget %}
    1115

    @@ -83,7 +87,7 @@
    8387
    {% block datetime_widget %}
    8488
    {% spaceless %}
    8589
    {% if widget == 'single_text' %}
    86-
    {{ block('field_widget') }}
    90+
    {{ block('input') }}
    8791
    {% else %}
    8892
    <div {{ block('widget_container_attributes') }}>
    8993
    {{ form_errors(form.date) }}
    @@ -98,7 +102,7 @@
    98102
    {% block date_widget %}
    99103
    {% spaceless %}
    100104
    {% if widget == 'single_text' %}
    101-
    {{ block('field_widget') }}
    105+
    {{ block('input') }}
    102106
    {% else %}
    103107
    <div {{ block('widget_container_attributes') }}>
    104108
    {{ date_pattern|replace({
    @@ -114,7 +118,7 @@
    114118
    {% block time_widget %}
    115119
    {% spaceless %}
    116120
    {% if widget == 'single_text' %}
    117-
    {{ block('field_widget') }}
    121+
    {{ block('input') }}
    118122
    {% else %}
    119123
    <div {{ block('widget_container_attributes') }}>
    120124
    {{ 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 %}
    @@ -127,67 +131,60 @@
    127131
    {% spaceless %}
    128132
    {# type="number" doesn't work with floats #}
    129133
    {% set type = type|default('text') %}
    130-
    {{ block('field_widget') }}
    134+
    {{ block('input') }}
    131135
    {% endspaceless %}
    132136
    {% endblock number_widget %}
    133137

    134138
    {% block integer_widget %}
    135139
    {% spaceless %}
    136140
    {% set type = type|default('number') %}
    137-
    {{ block('field_widget') }}
    141+
    {{ block('input') }}
    138142
    {% endspaceless %}
    139143
    {% endblock integer_widget %}
    140144

    141145
    {% block money_widget %}
    142146
    {% spaceless %}
    143-
    {{ money_pattern|replace({ '{{ widget }}': block('field_widget') })|raw }}
    147+
    {{ money_pattern|replace({ '{{ widget }}': block('input') })|raw }}
    144148
    {% endspaceless %}
    145149
    {% endblock money_widget %}
    146150

    147151
    {% block url_widget %}
    148152
    {% spaceless %}
    149153
    {% set type = type|default('url') %}
    150-
    {{ block('field_widget') }}
    154+
    {{ block('input') }}
    151155
    {% endspaceless %}
    152156
    {% endblock url_widget %}
    153157

    154158
    {% block search_widget %}
    155159
    {% spaceless %}
    156160
    {% set type = type|default('search') %}
    157-
    {{ block('field_widget') }}
    161+
    {{ block('input') }}
    158162
    {% endspaceless %}
    159163
    {% endblock search_widget %}
    160164

    161165
    {% block percent_widget %}
    162166
    {% spaceless %}
    163167
    {% set type = type|default('text') %}
    164-
    {{ block('field_widget') }} %
    168+
    {{ block('input') }} %
    165169
    {% endspaceless %}
    166170
    {% endblock percent_widget %}
    167171

    168-
    {% block field_widget %}
    169-
    {% spaceless %}
    170-
    {% set type = type|default('text') %}
    171-
    <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
    172-
    {% endspaceless %}
    173-
    {% endblock field_widget %}
    174-
    175172
    {% block password_widget %}
    176173
    {% spaceless %}
    177174
    {% set type = type|default('password') %}
    178-
    {{ block('field_widget') }}
    175+
    {{ block('input') }}
    179176
    {% endspaceless %}
    180177
    {% endblock password_widget %}
    181178

    182179
    {% block hidden_widget %}
    183180
    {% set type = type|default('hidden') %}
    184-
    {{ block('field_widget') }}
    181+
    {{ block('input') }}
    185182
    {% endblock hidden_widget %}
    186183

    187184
    {% block email_widget %}
    188185
    {% spaceless %}
    189186
    {% set type = type|default('email') %}
    190-
    {{ block('field_widget') }}
    187+
    {{ block('input') }}
    191188
    {% endspaceless %}
    192189
    {% endblock email_widget %}
    193190

    @@ -202,15 +199,11 @@
    202199
    {% endspaceless %}
    203200
    {% endblock %}
    204201

    205-
    {% block field_label %}
    206-
    {% spaceless %}
    207-
    {% set attr = attr|merge({'for': id}) %}
    208-
    {{ block('generic_label') }}
    209-
    {% endspaceless %}
    210-
    {% endblock field_label %}
    211-
    212202
    {% block form_label %}
    213203
    {% spaceless %}
    204+
    {% if form.children|length == 0 %}
    205+
    {% set attr = attr|merge({'for': id}) %}
    206+
    {% endif %}
    214207
    {{ block('generic_label') }}
    215208
    {% endspaceless %}
    216209
    {% endblock form_label %}
    @@ -219,24 +212,17 @@
    219212

    220213
    {% block repeated_row %}
    221214
    {% spaceless %}
    222-
    {{ block('field_rows') }}
    215+
    {{ block('form_rows') }}
    223216
    {% endspaceless %}
    224217
    {% endblock repeated_row %}
    225218

    226-
    {% block field_row %}
    227-
    {% spaceless %}
    228-
    <div>
    229-
    {{ form_label(form, label|default(null)) }}
    230-
    {{ form_errors(form) }}
    231-
    {{ form_widget(form) }}
    232-
    </div>
    233-
    {% endspaceless %}
    234-
    {% endblock field_row %}
    235-
    236219
    {% block form_row %}
    237220
    {% spaceless %}
    238221
    <div>
    239222
    {{ form_label(form, label|default(null)) }}
    223+
    {% if form.children|length == 0 %}
    224+
    {{ form_errors(form) }}
    225+
    {% endif %}
    240226
    {{ form_widget(form) }}
    241227
    </div>
    242228
    {% endspaceless %}
    @@ -248,13 +234,13 @@
    248234

    249235
    {# Misc #}
    250236

    251-
    {% block field_enctype %}
    237+
    {% block form_enctype %}
    252238
    {% spaceless %}
    253239
    {% if multipart %}enctype="multipart/form-data"{% endif %}
    254240
    {% endspaceless %}
    255-
    {% endblock field_enctype %}
    241+
    {% endblock form_enctype %}
    256242

    257-
    {% block field_errors %}
    243+
    {% block form_errors %}
    258244
    {% spaceless %}
    259245
    {% if errors|length > 0 %}
    260246
    <ul>
    @@ -270,28 +256,35 @@
    270256
    </ul>
    271257
    {% endif %}
    272258
    {% endspaceless %}
    273-
    {% endblock field_errors %}
    259+
    {% endblock form_errors %}
    274260

    275-
    {% block field_rest %}
    261+
    {% block form_rest %}
    276262
    {% spaceless %}
    277263
    {% for child in form %}
    278264
    {% if not child.rendered %}
    279265
    {{ form_row(child) }}
    280266
    {% endif %}
    281267
    {% endfor %}
    282268
    {% endspaceless %}
    283-
    {% endblock field_rest %}
    269+
    {% endblock form_rest %}
    284270

    285271
    {# Support #}
    286272

    287-
    {% block field_rows %}
    273+
    {% block form_rows %}
    288274
    {% spaceless %}
    289275
    {{ form_errors(form) }}
    290276
    {% for child in form %}
    291277
    {{ form_row(child) }}
    292278
    {% endfor %}
    293279
    {% endspaceless %}
    294-
    {% endblock field_rows %}
    280+
    {% endblock form_rows %}
    281+
    282+
    {% block input %}
    283+
    {% spaceless %}
    284+
    {% set type = type|default('text') %}
    285+
    <input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
    286+
    {% endspaceless %}
    287+
    {% endblock input %}
    295288

    296289
    {% block widget_attributes %}
    297290
    {% spaceless %}
    @@ -306,3 +299,47 @@
    306299
    {% for attrname,attrvalue in attr %}{{attrname}}="{{attrvalue}}" {% endfor %}
    307300
    {% endspaceless %}
    308301
    {% endblock widget_container_attributes %}
    302+
    303+
    {# Deprecated in Symfony 2.1, to be removed in 2.3 #}
    304+
    305+
    {% block field_widget %}
    306+
    {% spaceless %}
    307+
    {{ block('input') }}
    308+
    {% endspaceless %}
    309+
    {% endblock field_widget %}
    310+
    311+
    {% block field_label %}
    312+
    {% spaceless %}
    313+
    {{ block('form_label') }}
    314+
    {% endspaceless %}
    315+
    {% endblock field_label %}
    316+
    317+
    {% block field_row %}
    318+
    {% spaceless %}
    319+
    {{ block('form_row') }}
    320+
    {% endspaceless %}
    321+
    {% endblock field_row %}
    322+
    323+
    {% block field_enctype %}
    324+
    {% spaceless %}
    325+
    {{ block('form_enctype') }}
    326+
    {% endspaceless %}
    327+
    {% endblock field_enctype %}
    328+
    329+
    {% block field_errors %}
    330+
    {% spaceless %}
    331+
    {{ block('form_errors') }}
    332+
    {% endspaceless %}
    333+
    {% endblock field_errors %}
    334+
    335+
    {% block field_rest %}
    336+
    {% spaceless %}
    337+
    {{ block('form_rest') }}
    338+
    {% endspaceless %}
    339+
    {% endblock field_rest %}
    340+
    341+
    {% block field_rows %}
    342+
    {% spaceless %}
    343+
    {{ block('form_rows') }}
    344+
    {% endspaceless %}
    345+
    {% endblock field_rows %}
    Lines changed: 21 additions & 24 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,26 +1,15 @@
    11
    {% use "form_div_layout.html.twig" %}
    22

    3-
    {% block field_row %}
    4-
    {% spaceless %}
    5-
    <tr>
    6-
    <td>
    7-
    {{ form_label(form, label|default(null)) }}
    8-
    </td>
    9-
    <td>
    10-
    {{ form_errors(form) }}
    11-
    {{ form_widget(form) }}
    12-
    </td>
    13-
    </tr>
    14-
    {% endspaceless %}
    15-
    {% endblock field_row %}
    16-
    173
    {% block form_row %}
    184
    {% spaceless %}
    195
    <tr>
    206
    <td>
    217
    {{ form_label(form, label|default(null)) }}
    228
    </td>
    239
    <td>
    10+
    {% if form.children|length == 0 %}
    11+
    {{ form_errors(form) }}
    12+
    {% endif %}
    2413
    {{ form_widget(form) }}
    2514
    </td>
    2615
    </tr>
    @@ -29,12 +18,16 @@
    2918

    3019
    {% block form_errors %}
    3120
    {% spaceless %}
    32-
    {% if errors|length > 0 %}
    33-
    <tr>
    34-
    <td colspan="2">
    35-
    {{ block('field_errors') }}
    36-
    </td>
    37-
    </tr>
    21+
    {% if form.children|length > 0 %}
    22+
    {% if errors|length > 0 %}
    23+
    <tr>
    24+
    <td colspan="2">
    25+
    {{ parent() }}
    26+
    </td>
    27+
    </tr>
    28+
    {% endif %}
    29+
    {% else %}
    30+
    {{ parent() }}
    3831
    {% endif %}
    3932
    {% endspaceless %}
    4033
    {% endblock form_errors %}
    @@ -51,9 +44,13 @@
    5144

    5245
    {% block form_widget %}
    5346
    {% spaceless %}
    54-
    <table {{ block('widget_container_attributes') }}>
    55-
    {{ block('field_rows') }}
    56-
    {{ form_rest(form) }}
    57-
    </table>
    47+
    {% if form.children|length > 0 %}
    48+
    <table {{ block('widget_container_attributes') }}>
    49+
    {{ block('form_rows') }}
    50+
    {{ form_rest(form) }}
    51+
    </table>
    52+
    {% else %}
    53+
    {{ parent() }}
    54+
    {% endif %}
    5855
    {% endspaceless %}
    5956
    {% endblock form_widget %}
    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,3 +1,3 @@
    1-
    {% block field_label %}
    1+
    {% block form_label %}
    22
    <label>child</label>
    3-
    {% endblock field_label %}
    3+
    {% endblock form_label %}
    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,3 +1,3 @@
    1-
    {% block field_label %}
    1+
    {% block form_label %}
    22
    <label>parent</label>
    3-
    {% endblock field_label %}
    3+
    {% endblock form_label %}
    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,6 +1,6 @@
    1-
    {% block field_widget %}
    1+
    {% block input %}
    22
    {% spaceless %}
    33
    {% set type = type|default('text') %}
    44
    <input type="{{ type }}" {{ block('attributes') }} value="{{ value }}" rel="theme" />
    55
    {% endspaceless %}
    6-
    {% endblock field_widget %}
    6+
    {% endblock input %}

    0 commit comments

    Comments
     (0)
    0