Commit Graph

54015 Commits

Author SHA1 Message Date
Robin Chalas
2c99518454 minor #40553 [Contracts] Fix branch name in README.md links (chalasr)
This PR was merged into the 4.4 branch.

Discussion
----------

[Contracts] Fix branch name in README.md links

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

c5c47f11a4 [Contracts] Fix branch name in README.md links
2021-03-23 17:08:21 +01:00
Robin Chalas
c5c47f11a4 [Contracts] Fix branch name in README.md links 2021-03-23 16:25:38 +01:00
Robin Chalas
c752257be3 Merge branch '5.2' into 5.x
* 5.2:
  [Console] minor fix
  [Command] fix emojis messing up the line width
  [Validator] Avoid triggering the autoloader for user-input values
  Hardening Security - Unserialize DumpDataCollector
  Security hardening - Rate limiter
  [FrameworkBundle] ensure TestBrowserToken::$firewallName is serialized
  Fixed parsing deprecated definitions without message key
  improve login throttling rate limiter requirement message
  [HttpClient] remove using $http_response_header
  [Security] Handle properly 'auto' option for remember me cookie security
2021-03-23 15:20:07 +01:00
Robin Chalas
2da27bbd27 feature #40550 [Notifier] Move abstract test cases to namespace (OskarStark)
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Notifier] Move abstract test cases to  namespace

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no (only fixes builds)
| New feature?  | yes (not sure about a changeling entry)
| Deprecations? | no
| Tickets       | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | no

This enables BC promise for the abstract test classes, like for other ones.

As we ignore current `/Tests` directory in `.gitattributes`, builds will fail if `symfony/notifier` is installed as dist.

Commits
-------

33ba3c755d [Notifier] Move abstract test cases to  namespace
2021-03-23 15:00:06 +01:00
Nicolas Grekas
e494b389f3 bug #40541 Fixed parsing deprecated definitions without message key (adamwojs)
This PR was merged into the 5.2 branch.

Discussion
----------

Fixed parsing deprecated definitions without message key

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

### Steps to reproduce

1. Create service/alias definition and mark it as deprecated without specifying message key as shown in https://symfony.com/doc/5.2/service_container/alias_private.html#deprecating-service-aliases. For example:

```yaml
services:
    service_without_deprecation_message:
        class: Foo
        deprecated:
            package: vendor/package
            version: 1.1

    alias_without_deprecation_message:
        alias: foobar
        deprecated:
            package: vendor/package
            version: 1.1
```

2. Clear cache by running `php bin/console cache:clear`

### Actual behaviour

`Symfony\Component\Config\Exception\LoaderLoadException` exception is thrown with the following message: `Warning: Undefined array key "message" (...)`

See https://gist.github.com/adamwojs/5bac85d4326d8fbe6f52a357fa6e57e6 for full stactrace.

### Excepted behaviour

Given definitions are loaded correctly. Default service/alias deprecation message is used as shown in linked documentation page.

Commits
-------

d585b64953 Fixed parsing deprecated definitions without message key
2021-03-23 13:46:26 +01:00
Nicolas Grekas
88d222d856 Merge branch '4.4' into 5.2
* 4.4:
  [Console] minor fix
  [Validator] Avoid triggering the autoloader for user-input values
  Hardening Security - Unserialize DumpDataCollector
  [HttpClient] remove using $http_response_header
  [Security] Handle properly 'auto' option for remember me cookie security
2021-03-23 13:45:44 +01:00
Nicolas Grekas
55bd7f4be4 feature #40530 [Uid] Handle predefined namespaces keywords "dns", "url", "oid" and "x500" (fancyweb)
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Uid] Handle predefined namespaces keywords "dns", "url", "oid" and "x500"

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Before: `uuid:generate --name-based="https://symfony.com" --namespace=6ba7b811-9dad-11d1-80b4-00c04fd430c8`
After: `uuid:generate --name-based="https://symfony.com" --namespace=url`

Same for FWB configuration.

Commits
-------

ede46ac13a [Uid] Handle predefined namespaces keywords "dns", "url", "oid" and "x500"
2021-03-23 13:33:35 +01:00
Nicolas Grekas
9a8e2c2625 bug #40537 [Security] Handle properly 'auto' option for remember me cookie security (fliespl)
This PR was merged into the 4.4 branch.

Discussion
----------

[Security] Handle properly 'auto' option for remember me cookie security

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #40471
| License       | MIT
| Doc PR        | n/a

Manually setting remember_me cookie secure as auto is still is being set as secure one even if used over http.

This PR fixes this behaviour by converting auto to null prior setting it up for service.

Commits
-------

2bcf69c071 [Security] Handle properly 'auto' option for remember me cookie security
2021-03-23 13:31:44 +01:00
Nicolas Grekas
7eb4db6d9d [Console] minor fix 2021-03-23 13:24:21 +01:00
Nicolas Grekas
1044c0bd4b bug #40524 [Console] fix emojis messing up the line width (MarionLeHerisson)
This PR was submitted for the 5.x branch but it was merged into the 5.2 branch instead.

Discussion
----------

[Console] fix emojis messing up the line width

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix https://github.com/symfony/symfony/issues/37904
| License       | MIT

Description
========

The emojis, because they take as much space as two characters, would cause the console to display too many spaces to complete a line, which made it uneven, as described in the issue.

The fix uses the `width` function instead of `strlen`. To answer @ogizanagi's comment, yes it does work with "composed" emojis.

Before :

![image](https://user-images.githubusercontent.com/11477247/111832081-9d72b100-88f0-11eb-8eda-65ee480c898d.png)

After :

![image](https://user-images.githubusercontent.com/11477247/111832103-a6638280-88f0-11eb-802e-838d97f61c81.png)

Other changes
==========

Removed two unused lines of code, the value of `$messageLineLength` was never used.

Note
====
I'd like to add some tests, but I don't know how since I think this depends on console client width ?

Thanks for your reviews 🙏

Commits
-------

36b36dcecc [Command] fix emojis messing up the line width
2021-03-23 13:19:25 +01:00
Marion Hurteau
36b36dcecc [Command] fix emojis messing up the line width
add tests + removed irrelevant method
2021-03-23 13:19:11 +01:00
Nicolas Grekas
689056ef7f bug #40506 [Validator] Avoid triggering the autoloader for user-input values (Seldaek)
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Validator] Avoid triggering the autoloader for user-input values

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Following-up to https://twitter.com/seldaek/status/1372450636361502721 - mostly to see if the build passes or if this breaks some undocumented/unclear-to-me assumptions.

Essentially using the `Valid` constraint should only validate objects if they exist as objects. If a user sends a string and that gets assigned to a property, `Valid` should not attempt autoloading that user-given string.

As far as I can tell, this is used in two places:

- acb32dd396/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php (L364-L365) where non-objects are anyway ignored, so this change is harmless there.
- acb32dd396/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php (L652-L660) where it's explicitly passing anything in there to get the proper exception, so my change makes sure that exception is thrown *before* autoloading attempts. I am just not 100% sure if there are cases where validateGenericNode will receive a class name as a string to validate in $value. I can't imagine why it would but that doesn't mean it's true.

Commits
-------

e45eb23ba2 [Validator] Avoid triggering the autoloader for user-input values
2021-03-23 12:26:37 +01:00
Jordi Boggiano
e45eb23ba2 [Validator] Avoid triggering the autoloader for user-input values 2021-03-23 12:25:54 +01:00
Nicolas Grekas
4c2f77e5b1 bug #40544 [FrameworkBundle] ensure TestBrowserToken::$firewallName is serialized (kbond)
This PR was merged into the 5.2 branch.

Discussion
----------

[FrameworkBundle] ensure TestBrowserToken::$firewallName is serialized

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | n/a
| License       | MIT
| Doc PR        | n/a

Fixes a bug introduced in #40368. When `TestBrowserToken` in unserialized, `$firewallName` is `null` so trying to access it via `getFirewallName` throws a `TypeError`.

Commits
-------

8ba12ece57 [FrameworkBundle] ensure TestBrowserToken::$firewallName is serialized
2021-03-23 12:16:14 +01:00
Oskar Stark
33ba3c755d [Notifier] Move abstract test cases to namespace
This enables BC promise for the abstract test classes, like for other ones.

As we ignore current `/Tests` directory in `.gitattributes`, builds will fail if `symfony/notifier` is installed as dist.
2021-03-23 10:42:26 +01:00
Nicolas Grekas
f84adc46f3 minor #40546 Security Hardening - unserialize DumpDataCollector (jderusse)
This PR was merged into the 4.4 branch.

Discussion
----------

Security Hardening - unserialize DumpDataCollector

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

214dbfec51 Hardening Security - Unserialize DumpDataCollector
2021-03-23 09:51:46 +01:00
Jérémy Derussé
214dbfec51
Hardening Security - Unserialize DumpDataCollector 2021-03-23 09:46:32 +01:00
Nyholm
0f4870b23f
bug #40547 [RateLimiter] Security hardening - Rate limiter (jderusse)
This PR was merged into the 5.2 branch.

Discussion
----------

[RateLimiter] Security hardening - Rate limiter

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | yes
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

e61553af4b Security hardening - Rate limiter
2021-03-23 08:09:52 +01:00
Jérémy Derussé
e61553af4b
Security hardening - Rate limiter 2021-03-22 20:26:15 +01:00
Alexander M. Turek
15764b4200 minor #40542 [WebLink] Remove symfony/http-foundation dependency (Nyholm)
This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[WebLink] Remove symfony/http-foundation dependency

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #40536
| License       | MIT
| Doc PR        |

Both me and @derrabus overlooked this.

Commits
-------

415c2a0b47 [WebLink] Remove symfony/http-foundation dependency
2021-03-22 16:30:20 +01:00
Nyholm
415c2a0b47 [WebLink] Remove symfony/http-foundation dependency 2021-03-22 16:30:12 +01:00
Kevin Bond
8ba12ece57
[FrameworkBundle] ensure TestBrowserToken::$firewallName is serialized 2021-03-22 10:43:01 -04:00
Nyholm
8c1f3aca39
feature #40536 [HttpFoundation][HttpKernel] Rename master request to main request (derrabus)
This PR was merged into the 5.3-dev branch.

Discussion
----------

[HttpFoundation][HttpKernel] Rename master request to main request

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | Fix #37509
| License       | MIT
| Doc PR        | TODO

Let's find a better term for "master request" because of the reasons described in https://github.com/symfony/symfony/issues/37509#issuecomment-749498154. This PR proposes the term main request instead.

Commits
-------

1fc2a04e00 Rename master request to main request
2021-03-22 14:40:41 +01:00
Alexander M. Turek
1fc2a04e00 Rename master request to main request 2021-03-22 14:14:48 +01:00
Adam Wójs
d585b64953 Fixed parsing deprecated definitions without message key 2021-03-22 12:10:24 +01:00
Fabien Potencier
602b52041a bug #40538 [HttpClient] remove using $http_response_header (nicolas-grekas)
This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] remove using $http_response_header

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Spotted after reading https://wiki.php.net/rfc/deprecations_php_8_1#predefined_variable_http_response_header

Commits
-------

b78f1dffc2 [HttpClient] remove using $http_response_header
2021-03-22 11:36:51 +01:00
Fabien Potencier
7611d24e06 minor #40539 [Security] improve login throttling rate limiter requirement message (jrushlow)
This PR was submitted for the 5.x branch but it was merged into the 5.2 branch instead.

Discussion
----------

[Security] improve login throttling rate limiter requirement message

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Provide the composer command to the user if the `rate-limiter` component is not installed when attempting to use login throttling.

Commits
-------

6958bdc0be improve login throttling rate limiter requirement message
2021-03-22 11:35:16 +01:00
Jesse Rushlow
6958bdc0be
improve login throttling rate limiter requirement message 2021-03-22 06:08:44 -04:00
Nicolas Grekas
b78f1dffc2 [HttpClient] remove using $http_response_header 2021-03-22 10:43:50 +01:00
flies
2bcf69c071 [Security] Handle properly 'auto' option for remember me cookie security 2021-03-22 09:54:48 +01:00
Alexander M. Turek
7873574335 Merge branch '5.2' into 5.x
* 5.2:
  [UID] refer to AbstractUid instead of "parent"
2021-03-22 02:11:47 +01:00
Robin Chalas
9bb312dc59 minor #40531 [Uid] refer to AbstractUid instead of "parent" (Nyholm)
This PR was merged into the 5.2 branch.

Discussion
----------

[Uid] refer to AbstractUid instead of "parent"

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Following @OskarStark's suggestion.

Except for internal code and test code, we do this on one more place. That is `LazyResponseEvent`, but that class is final so there is no need to change it.

Commits
-------

abe4ee5b56 [UID] refer to AbstractUid instead of "parent"
2021-03-21 19:45:58 +01:00
Thomas Calvet
ede46ac13a [Uid] Handle predefined namespaces keywords "dns", "url", "oid" and "x500" 2021-03-21 18:34:32 +01:00
Nyholm
abe4ee5b56
[UID] refer to AbstractUid instead of "parent" 2021-03-21 17:15:38 +01:00
Robin Chalas
d39596edab minor #40527 [Runtime] Dont use "parent" as type hint (Nyholm)
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Runtime] Dont use "parent" as type hint

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no (minor)
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

The type hint `parent` is weird and confusing. PHPStorm also warned be that it is not supported on PHP 7.2 and 7.3.

I replace this will `GenericRuntime` instead. It will make it easier to extend `SymfonyRuntime`.

Commits
-------

4f486e850a [Runtime] Dont use "parent" as type hint
2021-03-21 16:22:56 +01:00
Nyholm
4f486e850a
[Runtime] Dont use "parent" as type hint 2021-03-20 13:56:11 +01:00
Nicolas Grekas
1b93740325 CS fix 2021-03-19 19:00:13 +01:00
Nicolas Grekas
2edf4f8b61 bug #40521 [Uid] [GenerateUuidCommand] Compute a new \DateTimeImmutable every loop (fancyweb)
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Uid] [GenerateUuidCommand] Compute a new \DateTimeImmutable every loop

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Before (the timestamp is never increased):
```
➜  uuid:generate --time-based=now --count=3
eb017d96-88cf-11eb-a80e-c3dd8d58cd10
eb017d96-88cf-11eb-a80e-c3dd8d58cd10
eb017d96-88cf-11eb-a80e-c3dd8d58cd10
```

After:
```
➜  uuid:generate --time-based=now --count=3
0ef9ed97-88d0-11eb-a80e-c3dd8d58cd10
0ef9ed98-88d0-11eb-a80e-c3dd8d58cd10
0ef9ed99-88d0-11eb-a80e-c3dd8d58cd10
```

It it useful if time based is not the default in the factory.

Commits
-------

2135fc3e71 [Uid] [GenerateUuidCommand] Compute a new \DateTimeImmutable every loop
2021-03-19 18:49:45 +01:00
Thomas Calvet
2135fc3e71 [Uid] [GenerateUuidCommand] Compute a new \DateTimeImmutable every loop 2021-03-19 18:32:35 +01:00
Nyholm
6c0786b579
feature #40513 [Runtime] make GenericRuntime ... generic (nicolas-grekas)
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Runtime] make GenericRuntime ... generic

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

This PR will allow #40436 to move to https://github.com/symfony/psr-http-message-bridge
For the record, it builds on a prototype I wrote almost one year ago at https://github.com/tchwork/bootstrapper.

This PR makes the `GenericRuntime` implementation able to auto-discover runtime implementations for specific types.

It uses the autoloader for the discovery: when a closure-app requires or returns a type `Vendor\Foo`, it will use a convention and check if the class `Symfony\Runtime\Vendor\FooRuntime` exists. If yes, it will use it to resolve the corresponding type. Such runtime classes have to extend `GenericRuntime` so that they can use the protected API it provides. This requirement is aligned with the fact that the very convention proposed here is an implementation detail that works when using a `GenericRuntime` as the main runtime (This behavior can be overridden by providing explicit entries in the new `runtimes` option when booting the `GenericRuntime`.)

`SymfonyRuntime` can be used as both the main runtime or a type-specific runtime:
- when used as the main runtime, it configures the typical global-state for Symfony and has a fast codepath for Symfony types, while still being generic.
- it can also be used in another runtime as a way to resolve Symfony types (would typically be useful to #40436 for running Console apps in a PSR-based web app.)

Commits
-------

33e371e24d [Runtime] make GenericRuntime ... generic
2021-03-19 16:55:34 +01:00
Nicolas Grekas
485c896b4b Merge branch '5.2' into 5.x
* 5.2:
  [HttpKernel] do is_file check before include
  [PhpUnitBridge] fix reporting deprecations from DebugClassLoader
  [FrameworkBundle] skip deprecation in integration tests
  enable HTTP method overrides as early as possible with the HTTP cache
2021-03-19 12:02:33 +01:00
Nicolas Grekas
bd9e2208a0 Merge branch '4.4' into 5.2
* 4.4:
  [HttpKernel] do is_file check before include
  [PhpUnitBridge] fix reporting deprecations from DebugClassLoader
  [FrameworkBundle] skip deprecation in integration tests
2021-03-19 12:02:08 +01:00
Nicolas Grekas
a2d534ccf8 minor #40516 [HttpKernel] Add is_file() check before include (burned42)
This PR was merged into the 4.4 branch.

Discussion
----------

[HttpKernel] Add is_file() check before include

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes (?)
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

I recently noticed that on every deployment I got warnings reported by sentry from the `cache:clear` command.

> Warning: include(/var/www/html/var/cache/pro_/App_KernelProdContainer.php): failed to open stream: No such file or directory

In `Symfony\Component\HttpKernel\Kernel` [line 469](https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/HttpKernel/Kernel.php#L469)
 (on 4.4 it's on [line 536](https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/HttpKernel/Kernel.php#L536))

This is because the code tries to include the `$cachePath` without checking if it exists/is a file first. It seems like something similar was fixed some time ago already (https://github.com/symfony/symfony/pull/27249) some lines above.

This PR fixes the mentioned warnings for me.

I'm running on Symfony 5.2.5 at the moment, but the docs said that bugfixes should target branch 4.4 and new features should target 5.x, and I guess this could rather be seen as a bugfix than a new feature, so I branched off of 4.4 and also set this as target for the PR, I hope that's correct.

Commits
-------

8efcc17573 [HttpKernel] do is_file check before include
2021-03-19 12:01:36 +01:00
Nicolas Grekas
08306722ba bug #40508 [PhpUnitBridge] fix reporting deprecations from DebugClassLoader (nicolas-grekas)
This PR was merged into the 4.4 branch.

Discussion
----------

[PhpUnitBridge] fix reporting deprecations from DebugClassLoader

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #40400
| License       | MIT
| Doc PR        | -

Commits
-------

cb68aeab38 [PhpUnitBridge] fix reporting deprecations from DebugClassLoader
2021-03-19 11:58:33 +01:00
Romain
20f03677e3 [Serializer] Add a Custom End Of Line in CSV File 2021-03-19 11:55:40 +01:00
Nicolas Grekas
33e371e24d [Runtime] make GenericRuntime ... generic 2021-03-19 11:40:44 +01:00
Bernd Stellwag
8efcc17573 [HttpKernel] do is_file check before include
Trying to include a file that doesn't exist issues a warning. Doing an
is_file check beforehand should prevent those warnings.
2021-03-19 08:57:35 +01:00
Fabien Potencier
ab4fcf9bb7 bug #40497 [HttpFoundation] enable HTTP method overrides as early as possible with the HTTP cache (xabbuh)
This PR was merged into the 5.2 branch.

Discussion
----------

[HttpFoundation] enable HTTP method overrides as early as possible with the HTTP cache

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #40452
| License       | MIT
| Doc PR        |

Commits
-------

93e9337382 enable HTTP method overrides as early as possible with the HTTP cache
2021-03-18 16:34:32 +01:00
Alexander M. Turek
c8b48d8bbb feature #40430 [Form] Add "form_attr" FormType option (cristoforocervino)
This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[Form] Add "form_attr" FormType option

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      |no
| New feature?  | yes
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | [#15108](https://github.com/symfony/symfony-docs/pull/15108)

## What is this about

This PR add support for [`form` attribute](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form) to Symfony Form ([browser compatibility](https://caniuse.com/form-attribute)).

The `form` attribute allows form elements to override their associated form (which is their nearest ancestor form element by default). This is extremely useful to solve **nested form problem** and allows **form children** to be **rendered outside form tag** while still working as expected.

## New "form_attr" FormType option

#### form_attr
**type**: `bool` or `string` **default**: `false`

If set to `true` on a **root form**, adds [`form` attribute](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form) on every children with their root **form id**.
This allows you to render form children outside the form tag and avoid **nested form problem** in some situations while keeping the form working properly.

If set to `true` on a **child**, adds [`form` attribute](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form) on it with its **root form id**.
This allows you to render **that child** outside the form tag and avoid **nested form problem** in some situations while keeping the form working properly.

If root form has no `id` (this may happen by create an *unnamed* form), you can set it to a `string` identifier to be used at `FormView` level to link children and root form anyway.

## Usage on Root Form Example

#### Form Type
Enable the feature by setting `form_attr` to `true` on the root form.

```php
use Symfony\Component\Form\Extension\Core\Type;

class ListFilterType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('search', Type\SearchType::class)
            ->add('orderBy', Type\ChoiceType::class, [
                'choices' => [
                    // ...
                ],
            ])
            ->add('perPage', Type\ChoiceType::class, [
                'choices' => [
                    // ...
                ],
            ])
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefault('form_attr', true); // <--- Set this to true
    }
}

```

#### Twig

The following Twig template **works properly** even if form children are **outside** their form tag ([browser compatibility](https://caniuse.com/form-attribute)).

```twig

<div class="header-filters">
    {{ form_errors(form) }}
    {{ form_row(form.search) }} {# has attribute form="list_filter" #}
    {{ form_row(form.orderBy) }} {# has attribute form="list_filter" #}
</div>

<!-- -->
<!-- Some other HTML content, like a table or even another Symfony form -->
<!-- -->

<div class="footer-filters">
    {{ form_row(form.perPage) }} {# has attribute form="list_filter" #}
</div>
{{ form_start(form) }} {# id="list_filter" #}
{{ form_end(form) }}
```
 Every form elements work properly even outside form tag.

## Usage on Form Child Example

Enable the feature by setting `form_attr` to `true` on selected child.

```php
use Symfony\Component\Form\Extension\Core\Type;

class ListFilterType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('search', Type\SearchType::class)
            ->add('orderBy', Type\ChoiceType::class, [
                'choices' => [
                    // ...
                ],
            ])
            ->add('perPage', Type\ChoiceType::class, [
                'form_attr' => true,  // <--- Set this to true
                'choices' => [
                    // ...
                ],
            ])
    }
}

```

#### Twig

The following Twig template **works properly** even if `form.perPage` is **outside** form tag ([browser compatibility](https://caniuse.com/form-attribute)).

```twig

<div class="header-filters">
    {{ form_start(form) }} {# id="list_filter" #}
        {{ form_errors(form) }}
        {{ form_row(form.search) }}
        {{ form_row(form.orderBy) }}
    {{ form_end(form, {'render_rest': false}) }}
</div>

<!-- -->
<!-- Some other HTML content, like a table or even another Symfony form -->
<!-- -->

<div class="footer-filters">
    {{ form_row(form.perPage) }} {# has attribute form="list_filter" #}
</div>
```
 `form.perPage` element work properly even outside form tag.

Commits
-------

5f913cec74 [Form] Add "form_attr" FormType option
2021-03-18 16:04:16 +01:00
Cristoforo Cervino
5f913cec74 [Form] Add "form_attr" FormType option 2021-03-18 16:04:09 +01:00