Ver código fonte

Check if the method exists and add a more helpful message

Thomas Rabaix 13 anos atrás
pai
commit
a166c5cc0f
1 arquivos alterados com 5 adições e 1 exclusões
  1. 5 1
      Admin/AdminHelper.php

+ 5 - 1
Admin/AdminHelper.php

@@ -129,7 +129,7 @@ class AdminHelper
         $this->addNewInstance($form->getData(), $fieldDescription);
         $data[$childFormBuilder->getName()][] = $value;
 
-        $form = $admin->getFormBuilder($form->getData())->getForm();
+        $form = $admin->getFormBuilder()->getForm();
 
         // bind the data
         $form->bind($data);
@@ -151,6 +151,10 @@ class AdminHelper
 
         $method = sprintf('add%s', $this->camelize($mapping['fieldName']));
 
+        if (!method_exists($object, $method)) {
+            throw new \RuntimeException(sprintf('Please add a method %s in the %s class!', $method, get_class($object)));
+        }
+
         $object->$method($instance);
     }