1313
1414use JMS \Serializer \Context ;
1515use JMS \Serializer \Handler \FormErrorHandler as JMSFormErrorHandler ;
16+ use JMS \Serializer \Handler \SubscribingHandlerInterface ;
1617use JMS \Serializer \JsonSerializationVisitor ;
1718use JMS \Serializer \XmlSerializationVisitor ;
1819use Symfony \Component \Form \Form ;
1920use JMS \Serializer \YamlSerializationVisitor ;
20- use Symfony \Component \Translation \TranslatorInterface ;
2121
2222/**
2323 * Extend the JMS FormErrorHandler to include more informations when using the ViewHandler.
2424 */
25- class FormErrorHandler extends JMSFormErrorHandler
25+ class FormErrorHandler implements SubscribingHandlerInterface
2626{
27- private $ translator ;
27+ private $ formErrorHandler ;
2828
29- public function __construct (TranslatorInterface $ translator )
29+ public function __construct (JMSFormErrorHandler $ formErrorHandler )
3030 {
31- $ this ->translator = $ translator ;
32- parent ::__construct ($ translator );
31+ $ this ->formErrorHandler = $ formErrorHandler ;
32+ }
33+
34+ public static function getSubscribingMethods ()
35+ {
36+ return JMSFormErrorHandler::getSubscribingMethods ();
3337 }
3438
3539 public function serializeFormToXml (XmlSerializationVisitor $ visitor , Form $ form , array $ type , Context $ context = null )
@@ -52,20 +56,20 @@ public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form,
5256 $ errorsNode = $ visitor ->document ->createElement ('errors ' );
5357 $ visitor ->getCurrentNode ()->appendChild ($ errorsNode );
5458 $ visitor ->setCurrentNode ($ errorsNode );
55- parent :: serializeFormToXml ($ visitor , $ form , $ type );
59+ $ this -> formErrorHandler -> serializeFormToXml ($ visitor , $ form , $ type );
5660 $ visitor ->revertCurrentNode ();
5761
5862 return ;
5963 }
6064 }
6165
62- return parent :: serializeFormToXml ($ visitor , $ form , $ type );
66+ return $ this -> formErrorHandler -> serializeFormToXml ($ visitor , $ form , $ type );
6367 }
6468
6569 public function serializeFormToJson (JsonSerializationVisitor $ visitor , Form $ form , array $ type , Context $ context = null )
6670 {
6771 $ isRoot = null === $ visitor ->getRoot ();
68- $ result = $ this ->adaptFormArray (parent :: serializeFormToJson ($ visitor , $ form , $ type ), $ context );
72+ $ result = $ this ->adaptFormArray ($ this -> formErrorHandler -> serializeFormToJson ($ visitor , $ form , $ type ), $ context );
6973
7074 if ($ isRoot ) {
7175 $ visitor ->setRoot ($ result );
@@ -77,7 +81,7 @@ public function serializeFormToJson(JsonSerializationVisitor $visitor, Form $for
7781 public function serializeFormToYml (YamlSerializationVisitor $ visitor , Form $ form , array $ type , Context $ context = null )
7882 {
7983 $ isRoot = null === $ visitor ->getRoot ();
80- $ result = $ this ->adaptFormArray (parent :: serializeFormToYml ($ visitor , $ form , $ type ), $ context );
84+ $ result = $ this ->adaptFormArray ($ this -> formErrorHandler -> serializeFormToYml ($ visitor , $ form , $ type ), $ context );
8185
8286 if ($ isRoot ) {
8387 $ visitor ->setRoot ($ result );
@@ -86,6 +90,11 @@ public function serializeFormToYml(YamlSerializationVisitor $visitor, Form $form
8690 return $ result ;
8791 }
8892
93+ public function __call ($ name , $ arguments )
94+ {
95+ return call_user_func_array ([$ this ->formErrorHandler , $ name ], $ arguments );
96+ }
97+
8998 private function adaptFormArray (\ArrayObject $ serializedForm , Context $ context = null )
9099 {
91100 $ statusCode = $ this ->getStatusCode ($ context );
0 commit comments