فهرست منبع

[Form] text is now the default type when not explicitely set and when no data class is set

Fabien Potencier 14 سال پیش
والد
کامیت
fd97dd0059
1فایلهای تغییر یافته به همراه4 افزوده شده و 6 حذف شده
  1. 4 6
      src/Symfony/Component/Form/FormBuilder.php

+ 4 - 6
src/Symfony/Component/Form/FormBuilder.php

@@ -554,11 +554,13 @@ class FormBuilder
      * @param array                     $options The options
      *
      * @return FormBuilder The builder
-     *
-     * @throws FormException if the data class is not set when creating a property builder
      */
     public function create($name, $type = null, array $options = array())
     {
+        if (null === $type && !$this->dataClass) {
+            $type = 'text';
+        }
+
         if (null !== $type) {
             $builder = $this->getFormFactory()->createNamedBuilder(
                 $type,
@@ -567,10 +569,6 @@ class FormBuilder
                 $options
             );
         } else {
-            if (!$this->dataClass) {
-                throw new FormException(sprintf('The "%s" type cannot be guessed as the data class is not set. Provide the type manually (\'text\', \'password\', ...) or set the data class.', $name));
-            }
-
             $builder = $this->getFormFactory()->createBuilderForProperty(
                 $this->dataClass,
                 $name,