Skip to content

Commit 324ed3d

Browse files
committed
minor #12720 [Hackday] [Form] Deprecation messages for Form::bind() and Form::isBound() (stefanosala)
This PR was merged into the 2.7 branch. Discussion ---------- [Hackday] [Form] Deprecation messages for Form::bind() and Form::isBound() | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #12713, #12711 | License | MIT | Doc PR | - Commits ------- eb9e4d3 [Form] Add deprecation message for Form::bind() and Form::isBound()
2 parents f960ec7 + 0095061 commit 324ed3d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Form.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Form\Util\FormUtil;
2121
use Symfony\Component\Form\Util\InheritDataAwareIterator;
2222
use Symfony\Component\Form\Util\OrderedHashMap;
23+
use Symfony\Component\HttpFoundation\Request;
2324
use Symfony\Component\PropertyAccess\PropertyPath;
2425

2526
/**
@@ -505,6 +506,10 @@ public function handleRequest($request = null)
505506
*/
506507
public function submit($submittedData, $clearMissing = true)
507508
{
509+
if ($submittedData instanceof Request) {
510+
trigger_error('Passing a Symfony\Component\HttpFoundation\Request object to '.__CLASS__.'::bind() and '.__METHOD__.'() is deprecated since 2.3 and will be removed in 3.0, please use '.__CLASS__.'::handleRequest(). If you want to test whether the form was submitted separately, you can use the method '.__CLASS__.'::isSubmitted()', E_USER_DEPRECATED);
511+
}
512+
508513
if ($this->submitted) {
509514
throw new AlreadySubmittedException('A form can only be submitted once');
510515
}
@@ -676,6 +681,12 @@ public function submit($submittedData, $clearMissing = true)
676681
*/
677682
public function bind($submittedData)
678683
{
684+
// This method is deprecated for Request too, but the error is
685+
// triggered in Form::submit() method.
686+
if (!$submittedData instanceof Request) {
687+
trigger_error(__METHOD__.'() is deprecated since 2.3 and will be removed in 3.0. Please use '.__CLASS__.'::submit() instead.', E_USER_DEPRECATED);
688+
}
689+
679690
return $this->submit($submittedData);
680691
}
681692

@@ -713,6 +724,8 @@ public function isSubmitted()
713724
*/
714725
public function isBound()
715726
{
727+
trigger_error(__METHOD__.'() is deprecated since 2.3 and will be removed in 3.0. Please use '.__CLASS__.'::isSubmitted() instead.', E_USER_DEPRECATED);
728+
716729
return $this->submitted;
717730
}
718731

0 commit comments

Comments
 (0)