bug #23254 [Form][TwigBridge] render hidden _method field in form_rest() (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form][TwigBridge] render hidden _method field in form_rest()

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14261
| License       | MIT
| Doc PR        |

Commits
-------

0ee3f57533 render hidden _method field in form_rest()
This commit is contained in:
Fabien Potencier 2017-06-21 12:28:21 -07:00
commit 7cc97b6e0b
3 changed files with 34 additions and 1 deletions

View File

@ -262,6 +262,7 @@
{%- endblock form -%}
{%- block form_start -%}
{%- do form.setMethodRendered() -%}
{% set method = method|upper %}
{%- if method in ["GET", "POST"] -%}
{% set form_method = method %}
@ -301,6 +302,20 @@
{{- form_row(child) -}}
{% endif %}
{%- endfor %}
{% if not form.methodRendered %}
{%- do form.setMethodRendered() -%}
{% set method = method|upper %}
{%- if method in ["GET", "POST"] -%}
{% set form_method = method %}
{%- else -%}
{% set form_method = "POST" %}
{%- endif -%}
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
{%- endif -%}
{% endif %}
{% endblock form_rest %}
{# Support #}

View File

@ -22,7 +22,7 @@
"require-dev": {
"symfony/asset": "~2.7",
"symfony/finder": "~2.3",
"symfony/form": "~2.7.26|^2.8.19",
"symfony/form": "~2.7.30|^2.8.23",
"symfony/http-kernel": "~2.3",
"symfony/intl": "~2.3",
"symfony/routing": "~2.2",
@ -36,6 +36,9 @@
"symfony/var-dumper": "~2.7.16|^2.8.9",
"symfony/expression-language": "~2.4"
},
"conflict": {
"symfony/form": "<2.7.30|~2.8,<2.8.23"
},
"suggest": {
"symfony/finder": "",
"symfony/asset": "For using the AssetExtension",

View File

@ -53,6 +53,8 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
*/
private $rendered = false;
private $methodRendered = false;
public function __construct(FormView $parent = null)
{
$this->parent = $parent;
@ -90,6 +92,19 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
return $this;
}
/**
* @return bool
*/
public function isMethodRendered()
{
return $this->methodRendered;
}
public function setMethodRendered()
{
$this->methodRendered = true;
}
/**
* Returns a child by name (implements \ArrayAccess).
*