浏览代码

Fix Form Component ....

Thomas Rabaix 13 年之前
父节点
当前提交
36fa1799de

+ 2 - 2
Form/EventListener/FormProxy.php

@@ -4,7 +4,7 @@ namespace Sonata\AdminBundle\Form\EventListener;
 
 use Symfony\Component\Form\FormInterface;
 use Symfony\Component\Form\FormError;
-use Symfony\Component\Form\FormViewInterface;
+use Symfony\Component\Form\FormView;
 
 class FormProxy implements \IteratorAggregate, FormInterface
 {
@@ -173,7 +173,7 @@ class FormProxy implements \IteratorAggregate, FormInterface
         return $this->__call('isRoot', func_get_args());
     }
 
-    public function createView(FormViewInterface $parent = null)
+    public function createView(FormView $parent = null)
     {
         return $this->__call('createView', func_get_args());
     }

+ 13 - 13
Form/Extension/Field/Type/FormTypeFieldExtension.php

@@ -84,9 +84,9 @@ class FormTypeFieldExtension extends AbstractTypeExtension
     }
 
     /**
-     * @param FormViewInterface $view
-     * @param FormInterface     $form
-     * @param array             $options
+     * @param FormView      $view
+     * @param FormInterface $form
+     * @param array         $options
      */
     public function buildView(FormView $view, FormInterface $form, array $options)
     {
@@ -97,34 +97,34 @@ class FormTypeFieldExtension extends AbstractTypeExtension
             $sonataAdmin['value'] = $form->getData();
 
             // add a new block types, so the Admin Form element can be tweaked based on the admin code
-            $types    = $view->getVar('types');
+            $types    = $view->vars['types'];
             $baseName = str_replace('.', '_', $sonataAdmin['field_description']->getAdmin()->getCode());
             $baseType = $types[count($types) - 1];
 
             $types[] = sprintf('%s_%s', $baseName, $baseType);
             $types[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['field_description']->getName(), $baseType);
-            
+
             if ($sonataAdmin['block_name']) {
                 $types[] = $sonataAdmin['block_name'];
             }
 
-            $view->setVar('types', $types);
-            $view->setVar('sonata_admin_enabled', true);
-            $view->setVar('sonata_admin', $sonataAdmin);
+            $view->vars['types'] = $types;
+            $view->vars['sonata_admin_enabled'] = true;
+            $view->vars['sonata_admin'] = $sonataAdmin;
 
-            $attr = $view->getVar('attr', array());
+            $attr = $view->vars['attr'];
 
             if (!isset($attr['class'])) {
                 $attr['class'] = $sonataAdmin['class'];
             }
 
-            $view->setVar('attr', $attr);
+            $view->vars['attr'] = $attr;
 
         } else {
-            $view->setVar('sonata_admin_enabled', false);
+            $view->vars['sonata_admin_enabled'] = false;
         }
 
-        $view->setVar('sonata_admin', $sonataAdmin);
+        $view->vars['sonata_admin'] = $sonataAdmin;
     }
 
     /**
@@ -139,7 +139,7 @@ class FormTypeFieldExtension extends AbstractTypeExtension
 
     /**
      * Sets the default options
-     * 
+     *
      * @param OptionsResolverInterface $resolver Options Resolver
      */
     public function setDefaultOptions(OptionsResolverInterface $resolver)

+ 3 - 3
Resources/views/CRUD/base_list.html.twig

@@ -180,15 +180,15 @@ file that was distributed with this source code.
                         {% for filter in admin.datagrid.filters %}
                         <tr id="filter_{{ filter.name }}_row" class="filter {{ filter.isActive ? 'active' : 'inactive' }}">
                                 <td class="filter-title">{{ admin.trans(filter.label) }}</td>
-                                <td class="filter-type">{{ form_widget(form.get(filter.formName).get('type')) }}</td>
-                                <td class="filter-value">{{ form_widget(form.get(filter.formName).get('value')) }}</td>
+                                <td class="filter-type">{{ form_widget(form.children[filter.formName].children['type']) }}</td>
+                                <td class="filter-value">{{ form_widget(form.children[filter.formName].children['value']) }}</td>
                             </tr>
                         {% endfor %}
                     </table>
 
                     <input type="hidden" name="filter[_page]" id="filter__page" value="1" />
 
-                    {% set foo = form.get('_page').setRendered() %}
+                    {% set foo = form.children['_page'].setRendered() %}
                     {{ form_rest(form) }}
 
                     <input type="submit" class="btn btn-primary" value="{% trans from 'SonataAdminBundle' %}btn_filter{% endtrans %}" />

+ 4 - 5
Tests/Admin/AdminHelperTest.php

@@ -50,11 +50,10 @@ class AdminHelperTest extends \PHPUnit_Framework_TestCase
         $pool = new Pool($container, 'title', 'logo.png');
         $helper = new AdminHelper($pool);
 
-        $formView = new FormView('test');
-        $formView->setVar('id', 'test');
-        $child = new FormView('test');
-        $child->setVar('id', 'test_elementId');
-        $formView->add($child);
+        $formView = new FormView();
+        $formView->vars['id'] = 'test';
+        $child = new FormView($formView);
+        $child->vars['id'] = 'test_elementId';
 
         $this->assertNull($helper->getChildFormView($formView, 'foo'));
         $this->isInstanceOf('Symfony\Component\Form\FormView', $helper->getChildFormView($formView, 'test_elementId'));