Thomas 14 роки тому
батько
коміт
29ac419a2b
4 змінених файлів з 23 додано та 28 видалено
  1. 12 22
      Admin/Admin.php
  2. 3 5
      Admin/FieldDescription.php
  3. 1 1
      Builder/FormBuilder.php
  4. 7 0
      Form/FormMapper.php

+ 12 - 22
Admin/Admin.php

@@ -236,7 +236,7 @@ abstract class Admin extends ContainerAware
         foreach ($selectedFields as $name => $options) {
 
             $description = new FieldDescription;
-
+            
             if (!is_array($options)) {
                 $name = $options;
                 $options = array();
@@ -565,18 +565,15 @@ abstract class Admin extends ContainerAware
 
         $mapper = new FormMapper($this->getFormBuilder(), $form, $this);
 
-        foreach ($this->getFormFieldDescriptions() as $fieldDescription) {
+        $this->buildFormFieldDescriptions();
 
-            if (!$fieldDescription->getType()) {
+        $this->configureFormFields($mapper);
 
-                continue;
-            }
+        foreach ($this->getFormFieldDescriptions() as $fieldDescription) {
 
             $mapper->add($fieldDescription);
         }
-
-        $this->configureFormFields($mapper);
-
+        
         return $form;
     }
 
@@ -594,18 +591,15 @@ abstract class Admin extends ContainerAware
 
         $mapper = new ListMapper($this->getListBuilder(), $list, $this);
 
-        foreach ($this->getListFieldDescriptions() as $fieldDescription) {
-
-            if (!$fieldDescription->getType()) {
+        $this->buildListFieldDescriptions();
+        
+        $this->configureListFields($mapper);
 
-                continue;
-            }
+        foreach ($this->getListFieldDescriptions() as $fieldDescription) {
 
             $mapper->add($fieldDescription);
         }
 
-        $this->configureListFields($mapper);
-
         return $list;
     }
 
@@ -624,18 +618,14 @@ abstract class Admin extends ContainerAware
 
         $mapper = new DatagridMapper($this->getDatagridBuilder(), $datagrid, $this);
 
-        foreach ($this->getFilterFieldDescriptions() as $fieldDescription) {
-
-            if (!$fieldDescription->getType()) {
+        $this->buildFilterFieldDescriptions();
+        $this->configureDatagridFilters($mapper);
 
-                continue;
-            }
+        foreach ($this->getFilterFieldDescriptions() as $fieldDescription) {
 
             $mapper->add($fieldDescription);
         }
 
-        $this->configureDatagridFilters($mapper);
-
         return $datagrid;
     }
 

+ 3 - 5
Admin/FieldDescription.php

@@ -15,9 +15,9 @@ namespace Sonata\BaseApplicationBundle\Admin;
  * A FieldDescription hold the information about a field. A typical
  * admin instance contains different collections of fields
  *
- * - formFields: used by the form
- * - listFields: used by the list
- * - filderFields: used by the list filter
+ * - form: used by the form
+ * - list: used by the list
+ * - filter: used by the list filter
  *
  * Some options are global accross the different contexts, other are
  * context specifics.
@@ -325,6 +325,4 @@ class FieldDescription
     {
         return $this->mappingType;
     }
-
-
 }

+ 1 - 1
Builder/FormBuilder.php

@@ -66,7 +66,7 @@ class FormBuilder implements FormBuilderInterface
         'country'    =>  'Symfony\\Component\\Form\\CountryField',
     );
 
-        /**
+    /**
      * return the field associated to a FieldDescription
      *   ie : build the embedded form from the related Admin instance
      *

+ 7 - 0
Form/FormMapper.php

@@ -67,11 +67,18 @@ class FormMapper
             $fieldDescription->setOptions($fieldDescriptionOptions);
             $fieldDescription->setName($name);
 
+            // set default configuration
             $this->formBuilder->fixFieldDescription($this->admin, $fieldDescription, $fieldDescriptionOptions);
+
+            // add the FieldDescription
             $this->admin->addFormFieldDescription($name, $fieldDescription);
 
         } else if (is_string($name) && $this->admin->hasFormFieldDescription($name)) {
             $fieldDescription = $this->admin->getFormFieldDescription($name);
+
+            // update configuration
+            $this->formBuilder->fixFieldDescription($this->admin, $fieldDescription, $fieldDescriptionOptions);
+            
         } else {
 
             throw new \RuntimeException('invalid state');