@@ -1013,7 +1013,7 @@ private function getFormFromCrawler(Crawler $form): SymfonyForm
1013
1013
$ formId = $ form ->attr ('id ' );
1014
1014
if ($ formId !== null ) {
1015
1015
$ fakeForm = $ fakeDom ->firstChild ;
1016
- $ topParent = $ form -> ancestors ( )->last ();
1016
+ $ topParent = $ this -> getAncestorsFor ( $ form )->last ();
1017
1017
$ fieldsByFormAttribute = $ topParent ->filter (
1018
1018
sprintf ('input[form=%s],select[form=%s],textarea[form=%s] ' , $ formId , $ formId , $ formId )
1019
1019
);
@@ -1044,7 +1044,7 @@ protected function getFormFor(Crawler $node): SymfonyForm
1044
1044
if (strcasecmp ($ node ->first ()->getNode (0 )->tagName , 'form ' ) === 0 ) {
1045
1045
$ form = $ node ->first ();
1046
1046
} else {
1047
- $ form = $ node -> ancestors ( )->filter ('form ' )->first ();
1047
+ $ form = $ this -> getAncestorsFor ( $ node )->filter ('form ' )->first ();
1048
1048
}
1049
1049
1050
1050
if (!$ form ) {
@@ -1059,6 +1059,24 @@ protected function getFormFor(Crawler $node): SymfonyForm
1059
1059
return $ this ->forms [$ identifier ];
1060
1060
}
1061
1061
1062
+ /**
1063
+ * Returns the ancestors of the passed SymfonyCrawler.
1064
+ *
1065
+ * symfony/dom-crawler deprecated parents() in favor of ancestors()
1066
+ * This provides backward compatibility with < 5.3.0-BETA-1
1067
+ *
1068
+ * @param SymfonyCrawler $crawler the crawler
1069
+ * @return SymfonyCrawler the ancestors
1070
+ */
1071
+ private function getAncestorsFor (SymfonyCrawler $ crawler ): SymfonyCrawler
1072
+ {
1073
+ if (method_exists ($ crawler , 'ancestors ' )) {
1074
+ return $ crawler ->ancestors ();
1075
+ }
1076
+
1077
+ return $ crawler ->parents ();
1078
+ }
1079
+
1062
1080
/**
1063
1081
* Returns an array of name => value pairs for the passed form.
1064
1082
*
0 commit comments