8000 [Form] Deprecated FieldType, which has been merged into FormType · symfony/symfony@fcb2227 · GitHub
[go: up one dir, main page]

Skip to content

Commit fcb2227

Browse files
committed
[Form] Deprecated FieldType, which has been merged into FormType
1 parent bfa7ef2 commit fcb2227
  • FormTable
  • Templating/Helper
  • Tests/Templating/Helper/Resources
  • Component/Form
  • Some content is hidden

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

    72 files changed

    +1016
    -826
    lines changed

    CHANGELOG-2.1.md

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -267,9 +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
    272272
    * 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"
    273276

    274277
    ### HttpFoundation
    275278

    UPGRADE-2.1.md

    Lines changed: 104 additions & 10 deletions
    Original file line numberDiff line numberDiff line change
    @@ -94,7 +94,7 @@
    9494
    ```
    9595
    * The custom factories for the firewall configuration are now
    9696
    registered during the build method of bundles instead of being registered
    97-
    by the end-user. This means that you will you need to remove the 'factories'
    97+
    by the end-user. This means that you will you need to remove the 'factories'
    9898
    keys in your security configuration.
    9999
    100100
    * The Firewall listener is now registered after the Router listener. This
    @@ -372,29 +372,29 @@
    372372
    return isset($options['widget']) && 'single_text' === $options['widget'] ? 'text' : 'choice';
    373373
    }
    374374
    ```
    375-
    375+
    376376
    * The methods `getDefaultOptions()` and `getAllowedOptionValues()` of form
    377377
    types no longer receive an option array.
    378-
    378+
    379379
    You can specify options that depend on other options using closures instead.
    380-
    380+
    381381
    Before:
    382-
    382+
    383383
    ```
    384384
    public function getDefaultOptions(array $options)
    385385
    {
    386386
    $defaultOptions = array();
    387-
    387+
    388388
    if ($options['multiple']) {
    389389
    $defaultOptions['empty_data'] = array();
    390390
    }
    391-
    391+
    392392
    return $defaultOptions;
    393393
    }
    394394
    ```
    395-
    395+
    396396
    After:
    397-
    397+
    398398
    ```
    399399
    public function getDefaultOptions()
    400400
    {
    @@ -405,7 +405,7 @@
    405405
    );
    406406
    }
    407407
    ```
    408-
    408+
    409409
    The second argument `$previousValue` does not have to be specified if not
    410410
    needed.
    411411
    @@ -425,6 +425,100 @@
    425425
    (or any other of the BIND events). In case you used the CallbackValidator
    426426
    class, you should now pass the callback directly to `addEventListener`.
    427427
    428+
    * FieldType was merged into FormType. FieldType itself was deprecated and
    429+
    will be removed in Symfony 2.3.
    430+
    431+
    ##### Update your field types
    432+
    433+
    You are advised to update your custom types that extend FieldType to extend
    434+
    FormType instead.
    435+
    436+
    Before:
    437+
    438+
    ```
    439+
    public function getParent(array $options)
    440+
    {
    441+
    return 'field';
    442+
    }
    443+
    ```
    444+
    445+
    After:
    446+
    447+
    ```
    448+
    public function getParent(array $options)
    449+
    {
    450+
    return 'form';
    451+
    }
    452+
    ```
    453+
    454+
    You can also remove the getParent() method as this is the default
    455+
    implementation in AbstractType.
    456+
    457+
    ##### Update your form themes
    458+
    459+
    Previously, FieldType was the super type for all other types. Now, since
    460+
    it is deprecated, FieldType is a subtype of FormType, which is now the base
    461+
    type for all other types.
    462+
    463+
    A consequence of this change is that any "form_*" blocks defined in your
    464+
    themes are now also used for other types that extend "field", unless you
    465+
    explicitely override the "field_*" or "mytype_*" blocks.
    466+
    467+
    "field_*" blocks are deprecated and will be unsupported as of Symfony 2.3.
    468+
    You should merge them into the corresponding "form_*" blocks instead.
    469+
    470+
    Before:
    471+
    472+
    ```
    473+
    {% block field_label %}
    474+
    {% spaceless %}
    475+
    {% set attr = attr|merge({'for': id}) %}
    476+
    {{ block('generic_label') }}
    477+
    {% endspaceless %}
    478+
    {% endblock field_label %}
    479+
    480+
    {% block form_label %}
    481+
    {% spaceless %}
    482+
    {{ block('generic_label') }}
    483+
    {% endspaceless %}
    484+
    {% endblock form_label %}
    485+
    ```
    486+
    487+
    After:
    488+
    489+
    ```
    490+
    {% block form_label %}
    491+
    {% spaceless %}
    492+
    {% if form.children|length == 0 %}
    493+
    {% set attr = attr|merge({'for': id}) %}
    494+
    {% endif %}
    495+
    {{ block('generic_label') }}
    496+
    {% endspaceless %}
    497+
    {% endblock form_label %}
    498+
    ```
    499+
    500+
    The block "field_widget" was renamed to "input" and is still supported.
    501+
    502+
    Before:
    503+
    504+
    ```
    505+
    {% block field_widget %}
    506+
    {% spaceless %}
    507+
    <!-- custom input tag -->
    508+
    {% endspaceless %}
    509+
    {% endblock field_widget %}
    510+
    ```
    511+
    512+
    After:
    513+
    514+
    ```
    515+
    {% block input %}
    516+
    {% spaceless %}
    517+
    <!-- custom input tag -->
    518+
    {% endspaceless %}
    519+
    {% endblock input %}
    520+
    ```
    521+
    428522
    ### Session
    429523
    430524
    * Flash messages now return an array based on their type. The old method is

    0 commit comments

    Comments
     (0)
    0