Преглед на файлове

Serialize only form child of type Form

In the latest symfony version forms could include also
Symfony\Component\Form\SubmitButton field type.

Since is possible that someone uses the same form both for viewing and
for serializing (ajax response) maybe it should be correct to convert
form childs only when they are an instance of Form and ignore others
instead of throwing and exception.
minayaserrano преди 11 години
родител
ревизия
d4bfc546bd
променени са 1 файла, в които са добавени 7 реда и са изтрити 3 реда
  1. 7 3
      src/JMS/Serializer/Handler/FormErrorHandler.php

+ 7 - 3
src/JMS/Serializer/Handler/FormErrorHandler.php

@@ -77,8 +77,10 @@ class FormErrorHandler implements SubscribingHandlerInterface
         }
         }
 
 
         foreach ($form->all() as $child) {
         foreach ($form->all() as $child) {
-            if (null !== $node = $this->serializeFormToXml($visitor, $child, array())) {
-                $formNode->appendChild($node);
+            if ($child instanceof Form) {
+                if (null !== $node = $this->serializeFormToXml($visitor, $child, array())) {
+                    $formNode->appendChild($node);
+                }
             }
             }
         }
         }
 
 
@@ -138,7 +140,9 @@ class FormErrorHandler implements SubscribingHandlerInterface
 
 
         $children = array();
         $children = array();
         foreach ($data->all() as $child) {
         foreach ($data->all() as $child) {
-            $children[$child->getName()] = $this->convertFormToArray($visitor, $child);
+            if ($child instanceof Form) {
+                $children[$child->getName()] = $this->convertFormToArray($visitor, $child);
+            }
         }
         }
 
 
         if ($children) {
         if ($children) {