Ver Fonte

continue to work on the form refactoring

Thomas Rabaix há 14 anos atrás
pai
commit
677e2f6450

+ 1 - 0
Builder/ORM/FormContractor.php

@@ -86,6 +86,7 @@ class FormContractor implements FormContractorInterface
         }
         }
 
 
         $options['class']         = $fieldDescription->getTargetEntity();
         $options['class']         = $fieldDescription->getTargetEntity();
+        $options['data_class']    = $fieldDescription->getTargetEntity();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
 
 
         if ($fieldDescription->getOption('edit') == 'list') {
         if ($fieldDescription->getOption('edit') == 'list') {

+ 4 - 2
Controller/HelperController.php

@@ -50,13 +50,15 @@ class HelperController extends Controller
 
 
         list($fieldDescription, $formBuilder) = $helper->appendFormFieldElement($admin, $elementId);
         list($fieldDescription, $formBuilder) = $helper->appendFormFieldElement($admin, $elementId);
 
 
+        $view = $helper->getChildFormView($formBuilder->getForm()->createView(), $elementId);
+
         // render the widget
         // render the widget
         // todo : fix this, the twig environment variable is not set inside the extension ...
         // todo : fix this, the twig environment variable is not set inside the extension ...
         $twig = $this->get('twig');
         $twig = $this->get('twig');
-        $extension = $twig->getExtension('sonata_admin');
+        $extension = $twig->getExtension('form');
         $extension->initRuntime($this->get('twig'));
         $extension->initRuntime($this->get('twig'));
 
 
-        return new Response($extension->renderFormElement($fieldDescription, $formBuilder->getForm()->createView(), $formBuilder->getData()));
+        return new Response($extension->renderWidget($view));
     }
     }
 
 
     public function retrieveFormFieldElementAction()
     public function retrieveFormFieldElementAction()

+ 19 - 12
Form/Extension/Field/Type/FormTypeFieldExtension.php

@@ -34,21 +34,22 @@ class FormTypeFieldExtension extends AbstractTypeExtension
     public function buildForm(FormBuilder $builder, array $options)
     public function buildForm(FormBuilder $builder, array $options)
     {
     {
         $sonataAdmin = array(
         $sonataAdmin = array(
-            'admin'  => null,
-            'object'    => null,
+            'name'      => null,
+            'admin'     => null,
             'value'     => null,
             'value'     => null,
             'edit'      => 'standard',
             'edit'      => 'standard',
-            'inline'    => 'natual',
+            'inline'    => 'natural',
             'field_description' => null,
             'field_description' => null,
         );
         );
 
 
+        $builder->setAttribute('sonata_admin_enabled', false);
+
         if ($options['sonata_field_description'] instanceof FieldDescriptionInterface) {
         if ($options['sonata_field_description'] instanceof FieldDescriptionInterface) {
             $fieldDescription = $options['sonata_field_description'];
             $fieldDescription = $options['sonata_field_description'];
 
 
-            $sonataAdmin['object']            = $fieldDescription->getAdmin()->getSubject();
-            $sonataAdmin['value']             = $this->getValueFromFieldDescription($sonataAdmin['object'], $fieldDescription);
             $sonataAdmin['admin']             = $fieldDescription->getAdmin();
             $sonataAdmin['admin']             = $fieldDescription->getAdmin();
             $sonataAdmin['field_description'] = $fieldDescription;
             $sonataAdmin['field_description'] = $fieldDescription;
+            $sonataAdmin['name']              = $fieldDescription->getName();
 
 
             $parentFieldDescription = $fieldDescription->getAdmin()->getParentFieldDescription();
             $parentFieldDescription = $fieldDescription->getAdmin()->getParentFieldDescription();
 
 
@@ -59,6 +60,8 @@ class FormTypeFieldExtension extends AbstractTypeExtension
                 $sonataAdmin['edit']    = $fieldDescription->getOption('edit', 'standard');
                 $sonataAdmin['edit']    = $fieldDescription->getOption('edit', 'standard');
                 $sonataAdmin['inline']  = $fieldDescription->getOption('inline', 'natural');
                 $sonataAdmin['inline']  = $fieldDescription->getOption('inline', 'natural');
             }
             }
+
+            $builder->setAttribute('sonata_admin_enabled', true);
         }
         }
 
 
         $builder->setAttribute('sonata_admin', $sonataAdmin);
         $builder->setAttribute('sonata_admin', $sonataAdmin);
@@ -66,7 +69,13 @@ class FormTypeFieldExtension extends AbstractTypeExtension
 
 
     public function buildView(FormView $view, FormInterface $form)
     public function buildView(FormView $view, FormInterface $form)
     {
     {
-        $view->set('sonata_admin', $form->getAttribute('sonata_admin'));
+        // avoid to add extra information not required by non admin field
+        if ($form->getAttribute('sonata_admin_enabled', true)) {
+            $sonataAdmin = $form->getAttribute('sonata_admin');
+            $sonataAdmin['value'] = $form->getData();
+
+            $view->set('sonata_admin', $sonataAdmin);
+        }
     }
     }
 
 
     /**
     /**
@@ -90,8 +99,6 @@ class FormTypeFieldExtension extends AbstractTypeExtension
     {
     {
         return array(
         return array(
             'sonata_admin'     => null,
             'sonata_admin'     => null,
-            'sonata_object'    => null,
-            'sonata_value'     => null,
             'sonata_field_description' => null,
             'sonata_field_description' => null,
         );
         );
     }
     }
@@ -118,14 +125,14 @@ class FormTypeFieldExtension extends AbstractTypeExtension
      */
      */
     public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription)
     public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription)
     {
     {
+        $value = null;
+
         if (!$object) {
         if (!$object) {
-            return null;
-            throw new \RunTimeException(sprintf('Object cannot be null - id: %s, field: %s ', $fieldDescription->getAdmin()->getCode(), $fieldDescription->getName()));
+            return $value;
         }
         }
 
 
-        $value = null;
         try {
         try {
-          $value = $fieldDescription->getValue($object);
+            $value = $fieldDescription->getValue($object);
         } catch (NoValueException $e) {
         } catch (NoValueException $e) {
             if ($fieldDescription->getAssociationAdmin()) {
             if ($fieldDescription->getAssociationAdmin()) {
                 $value = $fieldDescription->getAssociationAdmin()->getNewInstance();
                 $value = $fieldDescription->getAssociationAdmin()->getNewInstance();

+ 60 - 60
Resources/views/CRUD/edit_orm_many_association_script.html.twig

@@ -26,13 +26,13 @@ This code manage the many-to-[one|many] association field popup
         - if the parent has an objectId defined then the related input get updated
         - if the parent has an objectId defined then the related input get updated
         - if the parent has NO object then an ajax request is made to refresh the popup
         - if the parent has NO object then an ajax request is made to refresh the popup
     #}
     #}
-    var field_dialog_form_list_link_{{ form.vars.id }} = function(event) {
-        initialize_popup_{{ form.vars.id }}();
+    var field_dialog_form_list_link_{{ id }} = function(event) {
+        initialize_popup_{{ id }}();
 
 
         event.preventDefault();
         event.preventDefault();
         event.stopPropagation();
         event.stopPropagation();
 
 
-        var element = jQuery(this).parents('#field_dialog_{{ form.vars.id }} td.sonata-ba-list-field');
+        var element = jQuery(this).parents('#field_dialog_{{ id }} td.sonata-ba-list-field');
 
 
         // the user does does click on a row column
         // the user does does click on a row column
         if (element.length == 0) {
         if (element.length == 0) {
@@ -41,31 +41,31 @@ This code manage the many-to-[one|many] association field popup
                 type: 'GET',
                 type: 'GET',
                 url: jQuery(this).attr('href'),
                 url: jQuery(this).attr('href'),
                 success: function(html) {
                 success: function(html) {
-                   field_dialog_{{ form.vars.id }}.html(html);
+                   field_dialog_{{ id }}.html(html);
                 }
                 }
             });
             });
 
 
             return;
             return;
         }
         }
 
 
-        jQuery('#{{ form.vars.id }}').val(element.attr('objectId'));
-        jQuery('#{{ form.vars.id }}').trigger('change');
+        jQuery('#{{ id }}').val(element.attr('objectId'));
+        jQuery('#{{ id }}').trigger('change');
 
 
-        field_dialog_{{ form.vars.id }}.dialog('close');
+        field_dialog_{{ id }}.dialog('close');
     }
     }
 
 
 
 
     // handle the add link
     // handle the add link
-    var field_dialog_form_list_{{ form.vars.id }} = function(event) {
+    var field_dialog_form_list_{{ id }} = function(event) {
 
 
-        initialize_popup_{{ form.vars.id }}();
+        initialize_popup_{{ id }}();
 
 
         event.preventDefault();
         event.preventDefault();
         event.stopPropagation();
         event.stopPropagation();
 
 
         var a = jQuery(this);
         var a = jQuery(this);
 
 
-        field_dialog_{{ form.vars.id }}.html('');
+        field_dialog_{{ id }}.html('');
 
 
         // retrieve the form element from the related admin generator
         // retrieve the form element from the related admin generator
         jQuery.ajax({
         jQuery.ajax({
@@ -73,12 +73,12 @@ This code manage the many-to-[one|many] association field popup
             success: function(html) {
             success: function(html) {
 
 
                 // populate the popup container
                 // populate the popup container
-                field_dialog_{{ form.vars.id }}.html(html);
+                field_dialog_{{ id }}.html(html);
 
 
                 // capture the submit event to make an ajax call, ie : POST data to the
                 // capture the submit event to make an ajax call, ie : POST data to the
                 // related create admin
                 // related create admin
-                jQuery('a', field_dialog_{{ form.vars.id }}).live('click', field_dialog_form_list_link_{{ form.vars.id }});
-                jQuery('form', field_dialog_{{ form.vars.id }}).live('submit', function(event) {
+                jQuery('a', field_dialog_{{ id }}).live('click', field_dialog_form_list_link_{{ id }});
+                jQuery('form', field_dialog_{{ id }}).live('submit', function(event) {
                     event.preventDefault();
                     event.preventDefault();
 
 
                     var form = jQuery(this);
                     var form = jQuery(this);
@@ -88,13 +88,13 @@ This code manage the many-to-[one|many] association field popup
                         url: form.attr('action'),
                         url: form.attr('action'),
                         data: {_xml_http_request: true},
                         data: {_xml_http_request: true},
                         success: function(html) {
                         success: function(html) {
-                           field_dialog_{{ form.vars.id }}.html(html);
+                           field_dialog_{{ id }}.html(html);
                         }
                         }
                     });
                     });
                 });
                 });
 
 
                 // open the dialog in modal mode
                 // open the dialog in modal mode
-                field_dialog_{{ form.vars.id }}.dialog({
+                field_dialog_{{ id }}.dialog({
                     height: 'auto',
                     height: 'auto',
                     width: 980,
                     width: 980,
                     modal: true,
                     modal: true,
@@ -102,8 +102,8 @@ This code manage the many-to-[one|many] association field popup
                     title: '{{ sonata_admin.field_description.associationadmin.label }}',
                     title: '{{ sonata_admin.field_description.associationadmin.label }}',
                     close: function(event, ui) {
                     close: function(event, ui) {
                         // make sure we have a clean state
                         // make sure we have a clean state
-                        jQuery('a', field_dialog_{{ form.vars.id }}).die('click');
-                        jQuery('form', field_dialog_{{ form.vars.id }}).die('submit');
+                        jQuery('a', field_dialog_{{ id }}).die('click');
+                        jQuery('form', field_dialog_{{ id }}).die('submit');
                     }
                     }
                 });
                 });
             }
             }
@@ -111,44 +111,44 @@ This code manage the many-to-[one|many] association field popup
     };
     };
 
 
     // handle the add link
     // handle the add link
-    var field_dialog_form_add_{{ form.vars.id }} = function(event) {
-        initialize_popup_{{ form.vars.id }}();
+    var field_dialog_form_add_{{ id }} = function(event) {
+        initialize_popup_{{ id }}();
 
 
         event.preventDefault();
         event.preventDefault();
         event.stopPropagation();
         event.stopPropagation();
 
 
         var a = jQuery(this);
         var a = jQuery(this);
 
 
-        field_dialog_{{ form.vars.id }}.html('');
+        field_dialog_{{ id }}.html('');
 
 
-        Admin.log('[{{ form.vars.id }}|field_dialog_form_add] add link action');
+        Admin.log('[{{ id }}|field_dialog_form_add] add link action');
         // retrieve the form element from the related admin generator
         // retrieve the form element from the related admin generator
         jQuery.ajax({
         jQuery.ajax({
             url: a.attr('href'),
             url: a.attr('href'),
             success: function(html) {
             success: function(html) {
 
 
-                Admin.log('[{{ form.vars.id }}|field_dialog_form_add] ajax success', field_dialog_{{ form.vars.id }});
+                Admin.log('[{{ id }}|field_dialog_form_add] ajax success', field_dialog_{{ id }});
 
 
                 // populate the popup container
                 // populate the popup container
-                field_dialog_{{ form.vars.id }}.html(html);
+                field_dialog_{{ id }}.html(html);
 
 
                 // capture the submit event to make an ajax call, ie : POST data to the
                 // capture the submit event to make an ajax call, ie : POST data to the
                 // related create admin
                 // related create admin
-                jQuery('a', field_dialog_{{ form.vars.id }}).live('click', field_dialog_form_action_{{ form.vars.id }});
-                jQuery('form', field_dialog_{{ form.vars.id }}).live('submit', field_dialog_form_action_{{ form.vars.id }});
+                jQuery('a', field_dialog_{{ id }}).live('click', field_dialog_form_action_{{ id }});
+                jQuery('form', field_dialog_{{ id }}).live('submit', field_dialog_form_action_{{ id }});
 
 
                 // open the dialog in modal mode
                 // open the dialog in modal mode
-                field_dialog_{{ form.vars.id }}.dialog({
+                field_dialog_{{ id }}.dialog({
                     height: 'auto',
                     height: 'auto',
                     width: 650,
                     width: 650,
                     modal: true,
                     modal: true,
                     resizable: false,
                     resizable: false,
                     title: '{{ sonata_admin.field_description.associationadmin.label }}',
                     title: '{{ sonata_admin.field_description.associationadmin.label }}',
                     close: function(event, ui) {
                     close: function(event, ui) {
-                        Admin.log('[{{ form.vars.id }}|field_dialog_form_add] dialog closed - removing `live` events');
+                        Admin.log('[{{ id }}|field_dialog_form_add] dialog closed - removing `live` events');
                         // make sure we have a clean state
                         // make sure we have a clean state
-                        jQuery('a', field_dialog_{{ form.vars.id }}).die('click');
-                        jQuery('form', field_dialog_{{ form.vars.id }}).die('submit');
+                        jQuery('a', field_dialog_{{ id }}).die('click');
+                        jQuery('form', field_dialog_{{ id }}).die('submit');
                     }
                     }
                 });
                 });
             }
             }
@@ -156,13 +156,13 @@ This code manage the many-to-[one|many] association field popup
     };
     };
 
 
     // handle the post data
     // handle the post data
-    var field_dialog_form_action_{{ form.vars.id }} = function(event) {
+    var field_dialog_form_action_{{ id }} = function(event) {
 
 
         event.preventDefault();
         event.preventDefault();
         event.stopPropagation();
         event.stopPropagation();
 
 
-        Admin.log('[{{ form.vars.id }}|field_dialog_form_action] action catch', this);
-        initialize_popup_{{ form.vars.id }}();
+        Admin.log('[{{ id }}|field_dialog_form_action] action catch', this);
+        initialize_popup_{{ id }}();
 
 
         var element = jQuery(this);
         var element = jQuery(this);
 
 
@@ -178,7 +178,7 @@ This code manage the many-to-[one|many] association field popup
         }
         }
 
 
         if (element.hasClass('sonata-ba-action')) {
         if (element.hasClass('sonata-ba-action')) {
-            Admin.log('[{{ form.vars.id }}|field_dialog_form_action] reserved action stop catch all events');
+            Admin.log('[{{ id }}|field_dialog_form_action] reserved action stop catch all events');
             return;
             return;
         }
         }
 
 
@@ -188,7 +188,7 @@ This code manage the many-to-[one|many] association field popup
 
 
         var form = jQuery(this);
         var form = jQuery(this);
 
 
-        Admin.log('[{{ form.vars.id }}|field_dialog_form_action] execute ajax call');
+        Admin.log('[{{ id }}|field_dialog_form_action] execute ajax call');
 
 
         // the ajax post
         // the ajax post
         jQuery(form).ajaxSubmit({
         jQuery(form).ajaxSubmit({
@@ -197,31 +197,31 @@ This code manage the many-to-[one|many] association field popup
             data: data,
             data: data,
             success: function(data) {
             success: function(data) {
 
 
-                Admin.log('[{{ form.vars.id }}|field_dialog_form_action] ajax success');
+                Admin.log('[{{ id }}|field_dialog_form_action] ajax success');
                 if (typeof data == 'string') {
                 if (typeof data == 'string') {
-                    field_dialog_{{ form.vars.id }}.html(data);
+                    field_dialog_{{ id }}.html(data);
                     return;
                     return;
                 };
                 };
 
 
                 // if the crud action return ok, then the element has been added
                 // if the crud action return ok, then the element has been added
                 // so the widget container must be refresh with the last option available
                 // so the widget container must be refresh with the last option available
                 if (data.result == 'ok') {
                 if (data.result == 'ok') {
-                    field_dialog_{{ form.vars.id }}.dialog('close');
+                    field_dialog_{{ id }}.dialog('close');
 
 
                     {% if sonata_admin.field_description.options.edit == 'list' %}
                     {% if sonata_admin.field_description.options.edit == 'list' %}
                         {#
                         {#
                            in this case we update the hidden input, and call the change event to
                            in this case we update the hidden input, and call the change event to
                            retrieve the post information
                            retrieve the post information
                         #}
                         #}
-                        jQuery('#{{ form.vars.id }}').val(data.objectId);
-                        jQuery('#{{ form.vars.id }}').change();
+                        jQuery('#{{ id }}').val(data.objectId);
+                        jQuery('#{{ id }}').change();
 
 
                     {% else %}
                     {% else %}
 
 
                         // reload the form element
                         // reload the form element
-                        jQuery('#field_widget_{{ form.vars.id }}').closest('form').ajaxSubmit({
+                        jQuery('#field_widget_{{ id }}').closest('form').ajaxSubmit({
                             url: '{{ url('sonata_admin_retrieve_form_element', {
                             url: '{{ url('sonata_admin_retrieve_form_element', {
-                                'elementId': form.vars.id,
+                                'elementId': id,
                                 'objectId':  sonata_admin.admin.root.id(sonata_admin.admin.root.subject),
                                 'objectId':  sonata_admin.admin.root.id(sonata_admin.admin.root.subject),
                                 'uniqid':    sonata_admin.admin.root.uniqid,
                                 'uniqid':    sonata_admin.admin.root.uniqid,
                                 'code':      sonata_admin.admin.root.code
                                 'code':      sonata_admin.admin.root.code
@@ -229,7 +229,7 @@ This code manage the many-to-[one|many] association field popup
                             data: {_xml_http_request: true },
                             data: {_xml_http_request: true },
                             type: 'POST',
                             type: 'POST',
                             success: function(html) {
                             success: function(html) {
-                                jQuery('#field_container_{{ form.vars.id }}').replaceWith(html);
+                                jQuery('#field_container_{{ id }}').replaceWith(html);
                             }
                             }
                         });
                         });
 
 
@@ -239,29 +239,29 @@ This code manage the many-to-[one|many] association field popup
                 }
                 }
 
 
                 // otherwise, display form error
                 // otherwise, display form error
-                field_dialog_{{ form.vars.id }}.html(html);
+                field_dialog_{{ id }}.html(html);
 
 
-                Admin.add_pretty_errors(field_dialog_{{ form.vars.id }});
+                Admin.add_pretty_errors(field_dialog_{{ id }});
 
 
                 // reattach the event
                 // reattach the event
-                jQuery('form', field_dialog_{{ form.vars.id }}).submit(field_dialog_form_action_{{ form.vars.id }});
+                jQuery('form', field_dialog_{{ id }}).submit(field_dialog_form_action_{{ id }});
             }
             }
         });
         });
 
 
         return false;
         return false;
     }
     }
 
 
-    var field_dialog_{{ form.vars.id }} = false;
+    var field_dialog_{{ id }} = false;
 
 
-    function initialize_popup_{{ form.vars.id }}() {
+    function initialize_popup_{{ id }}() {
         // initialize component
         // initialize component
-        if (!field_dialog_{{ form.vars.id }}) {
-            field_dialog_{{ form.vars.id }} = jQuery("#field_dialog_{{ form.vars.id }}");
+        if (!field_dialog_{{ id }}) {
+            field_dialog_{{ id }} = jQuery("#field_dialog_{{ id }}");
 
 
             // move the dialog as a child of the root element, nested form breaks html ...
             // move the dialog as a child of the root element, nested form breaks html ...
-            jQuery(document).append(field_dialog_{{ form.vars.id }});
+            jQuery(document).append(field_dialog_{{ id }});
 
 
-            Admin.log('[{{ form.vars.id }}|field_dialog] move dialog container as a document child');
+            Admin.log('[{{ id }}|field_dialog] move dialog container as a document child');
         }
         }
     }
     }
 
 
@@ -270,17 +270,17 @@ This code manage the many-to-[one|many] association field popup
     #}
     #}
     // this function initialize the popup
     // this function initialize the popup
     // this can be only done this way has popup can be cascaded
     // this can be only done this way has popup can be cascaded
-    function start_field_dialog_form_add_{{ form.vars.id }}(event) {
+    function start_field_dialog_form_add_{{ id }}(event) {
         event.preventDefault();
         event.preventDefault();
 
 
         // remove the html event a
         // remove the html event a
         var a = jQuery(event.target).closest('a');
         var a = jQuery(event.target).closest('a');
         a.attr('onclick', '');
         a.attr('onclick', '');
 
 
-        initialize_popup_{{ form.vars.id }}();
+        initialize_popup_{{ id }}();
 
 
        // add the jQuery event to the a element
        // add the jQuery event to the a element
-        a.click(field_dialog_form_add_{{ form.vars.id }});
+        a.click(field_dialog_form_add_{{ id }});
 
 
         // trigger the event
         // trigger the event
         a.trigger('click');
         a.trigger('click');
@@ -288,7 +288,7 @@ This code manage the many-to-[one|many] association field popup
         return false;
         return false;
     }
     }
 
 
-    Admin.add_pretty_errors(field_dialog_{{ form.vars.id }});
+    Admin.add_pretty_errors(field_dialog_{{ id }});
 
 
 
 
     {% if sonata_admin.field_description.options.edit == 'list' %}
     {% if sonata_admin.field_description.options.edit == 'list' %}
@@ -297,17 +297,17 @@ This code manage the many-to-[one|many] association field popup
         #}
         #}
         // this function initialize the popup
         // this function initialize the popup
         // this can be only done this way has popup can be cascaded
         // this can be only done this way has popup can be cascaded
-        function start_field_dialog_form_list_{{ form.vars.id }}(event) {
+        function start_field_dialog_form_list_{{ id }}(event) {
             event.preventDefault();
             event.preventDefault();
 
 
             // remove the html event a
             // remove the html event a
             var a = jQuery(event.target).closest('a');
             var a = jQuery(event.target).closest('a');
             a.attr('onclick', '');
             a.attr('onclick', '');
 
 
-            initialize_popup_{{ form.vars.id }}();
+            initialize_popup_{{ id }}();
 
 
             // add the jQuery event to the a element
             // add the jQuery event to the a element
-            a.click(field_dialog_form_list_{{ form.vars.id }});
+            a.click(field_dialog_form_list_{{ id }});
 
 
             // trigger the event
             // trigger the event
             a.trigger('click');
             a.trigger('click');
@@ -320,7 +320,7 @@ This code manage the many-to-[one|many] association field popup
         #}
         #}
 
 
         // update the
         // update the
-        jQuery('#{{ form.vars.id }}').live('change', function(event) {
+        jQuery('#{{ id }}').live('change', function(event) {
             jQuery.ajax({
             jQuery.ajax({
                 type: 'GET',
                 type: 'GET',
                 url: '{{ url('sonata_admin_short_object_information', {
                 url: '{{ url('sonata_admin_short_object_information', {
@@ -329,7 +329,7 @@ This code manage the many-to-[one|many] association field popup
                     'code': sonata_admin.field_description.associationadmin.code
                     'code': sonata_admin.field_description.associationadmin.code
                 })}}'.replace('OBJECT_ID', jQuery(this).val()),
                 })}}'.replace('OBJECT_ID', jQuery(this).val()),
                 success: function(html) {
                 success: function(html) {
-                    jQuery('#field_widget_{{ form.vars.id }}').html(html);
+                    jQuery('#field_widget_{{ id }}').html(html);
                 }
                 }
             });
             });
         });
         });

+ 5 - 5
Resources/views/CRUD/edit_orm_many_to_many.html.twig

@@ -10,15 +10,15 @@ file that was distributed with this source code.
 #}
 #}
 
 
 {% if sonata_admin.field_description.associationadmin %}
 {% if sonata_admin.field_description.associationadmin %}
-    <div id="field_container_{{ form.vars.id }}">
-        <span id="field_widget_{{ form.vars.id }}" >
+    <div id="field_container_{{ id }}">
+        <span id="field_widget_{{ id }}" >
             {{ form_widget(form) }}
             {{ form_widget(form) }}
         </span>
         </span>
 
 
-        <span id="field_actions_{{ form.vars.id }}" >
+        <span id="field_actions_{{ id }}" >
             <a
             <a
                 href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
                 href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
-                onclick="start_field_dialog_form_add_{{ form.vars.id }}(event)"
+                onclick="start_field_dialog_form_add_{{ id }}(event)"
                 class="sonata-ba-action"
                 class="sonata-ba-action"
                 style="{% if not sonata_admin.field_description.associationadmin.isGranted('CREATE')%}display:none{% endif %}"
                 style="{% if not sonata_admin.field_description.associationadmin.isGranted('CREATE')%}display:none{% endif %}"
                 >
                 >
@@ -29,7 +29,7 @@ file that was distributed with this source code.
             </a>
             </a>
         </span>
         </span>
 
 
-        <div style="display: none" id="field_dialog_{{ form.vars.id }}">
+        <div style="display: none" id="field_dialog_{{ id }}">
         </div>
         </div>
     </div>
     </div>
 
 

+ 8 - 8
Resources/views/CRUD/edit_orm_many_to_one.html.twig

@@ -18,11 +18,11 @@ file that was distributed with this source code.
 
 
 {% else %}
 {% else %}
 
 
-    <div id="field_container_{{ form.vars.id }}">
+    <div id="field_container_{{ id }}">
 
 
         {% if sonata_admin.field_description.options.edit == 'list' %}
         {% if sonata_admin.field_description.options.edit == 'list' %}
-            <span id="field_widget_{{ form.vars.id }}" >
-                {% if admin.id(value) %}
+            <span id="field_widget_{{ id }}" >
+                {% if sonata_admin.admin.id(value) %}
                     {% render 'SonataAdminBundle:Helper:getShortObjectDescription' with {}, {
                     {% render 'SonataAdminBundle:Helper:getShortObjectDescription' with {}, {
                         'query': {
                         'query': {
                             'code':     sonata_admin.field_description.associationadmin.code,
                             'code':     sonata_admin.field_description.associationadmin.code,
@@ -36,16 +36,16 @@ file that was distributed with this source code.
                 {{ form_widget(form) }}
                 {{ form_widget(form) }}
             </span>
             </span>
         {% else %}
         {% else %}
-            <span id="field_widget_{{ form.vars.id }}" >
+            <span id="field_widget_{{ id }}" >
                 {{ form_widget(form) }}
                 {{ form_widget(form) }}
             </span>
             </span>
         {% endif %}
         {% endif %}
 
 
-        <span id="field_actions_{{ form.vars.id }}" >
+        <span id="field_actions_{{ id }}" >
 
 
             {% if sonata_admin.field_description.options.edit == 'list' %}
             {% if sonata_admin.field_description.options.edit == 'list' %}
                 <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('list') }}"
                 <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('list') }}"
-                    onclick="start_field_dialog_form_list_{{ form.vars.id }}(event)"
+                    onclick="start_field_dialog_form_list_{{ id }}(event)"
                     class="sonata-ba-action"
                     class="sonata-ba-action"
                     style="{% if not sonata_admin.field_description.associationadmin.isGranted('LIST')%}display:none{% endif %}"
                     style="{% if not sonata_admin.field_description.associationadmin.isGranted('LIST')%}display:none{% endif %}"
                     >
                     >
@@ -56,7 +56,7 @@ file that was distributed with this source code.
             {% endif %}
             {% endif %}
 
 
             <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
             <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
-                onclick="start_field_dialog_form_add_{{ form.vars.id }}(event)"
+                onclick="start_field_dialog_form_add_{{ id }}(event)"
                 class="sonata-ba-action"
                 class="sonata-ba-action"
                 style="{% if not sonata_admin.field_description.associationadmin.isGranted('CREATE')%}display:none{% endif %}"
                 style="{% if not sonata_admin.field_description.associationadmin.isGranted('CREATE')%}display:none{% endif %}"
                 >
                 >
@@ -66,7 +66,7 @@ file that was distributed with this source code.
             </a>
             </a>
         </span>
         </span>
 
 
-        <div class="container sonata-ba-modal sonata-ba-modal-edit-one-to-one" style="display: none" id="field_dialog_{{ form.vars.id }}">
+        <div class="container sonata-ba-modal sonata-ba-modal-edit-one-to-one" style="display: none" id="field_dialog_{{ id }}">
 
 
         </div>
         </div>
     </div>
     </div>

+ 7 - 7
Resources/views/CRUD/edit_orm_one_association_script.html.twig

@@ -23,7 +23,7 @@ This code manage the one-to-many association field popup
     <!-- edit one association -->
     <!-- edit one association -->
 
 
     // handle the add link
     // handle the add link
-    var field_add_{{ form.vars.id }} = function(event) {
+    var field_add_{{ id }} = function(event) {
 
 
         event.preventDefault();
         event.preventDefault();
         event.stopPropagation();
         event.stopPropagation();
@@ -34,14 +34,14 @@ This code manage the one-to-many association field popup
         jQuery(form).ajaxSubmit({
         jQuery(form).ajaxSubmit({
             url: '{{ url('sonata_admin_append_form_element', {
             url: '{{ url('sonata_admin_append_form_element', {
                 'code':      sonata_admin.admin.root.code,
                 'code':      sonata_admin.admin.root.code,
-                'elementId': form.vars.id,
+                'elementId': id,
                 'objectId':  sonata_admin.admin.root.subject.id,
                 'objectId':  sonata_admin.admin.root.subject.id,
                 'uniqid':    sonata_admin.admin.root.uniqid
                 'uniqid':    sonata_admin.admin.root.uniqid
             }) }}',
             }) }}',
             type: "POST",
             type: "POST",
             data: { _xml_http_request: true },
             data: { _xml_http_request: true },
             success: function(html) {
             success: function(html) {
-                jQuery('#sonata-ba-field-container-{{ form.vars.id }}')
+                jQuery('#field_container_{{ id }}')
                     .replaceWith(html) // replace the html
                     .replaceWith(html) // replace the html
                     .trigger('sonata.add_element');
                     .trigger('sonata.add_element');
             }
             }
@@ -50,11 +50,11 @@ This code manage the one-to-many association field popup
         return false;
         return false;
     };
     };
 
 
-    var field_widget_{{ form.vars.id }} = false;
+    var field_widget_{{ id }} = false;
 
 
     // this function initialize the popup
     // this function initialize the popup
     // this can be only done this way has popup can be cascaded
     // this can be only done this way has popup can be cascaded
-    function start_field_retrieve_{{ form.vars.id }}(event) {
+    function start_field_retrieve_{{ id }}(event) {
         event.preventDefault();
         event.preventDefault();
 
 
         // remove the html event a
         // remove the html event a
@@ -62,10 +62,10 @@ This code manage the one-to-many association field popup
         a.attr('onclick', '');
         a.attr('onclick', '');
 
 
         // initialize component
         // initialize component
-        field_widget_{{ form.vars.id }} = jQuery("#field_widget_{{ form.vars.id }}");
+        field_widget_{{ id }} = jQuery("#field_widget_{{ id }}");
 
 
         // add the jQuery event to the a element
         // add the jQuery event to the a element
-        a.click(field_add_{{ form.vars.id }});
+        a.click(field_add_{{ id }});
 
 
         // trigger the event
         // trigger the event
         a.trigger('click');
         a.trigger('click');

+ 8 - 8
Resources/views/CRUD/edit_orm_one_to_one.html.twig

@@ -16,14 +16,14 @@ file that was distributed with this source code.
         {{ form_row(form.getChild(field_description.name)) }}
         {{ form_row(form.getChild(field_description.name)) }}
     {% endfor %}
     {% endfor %}
 {% else %}
 {% else %}
-    <div id="field_container_{{ form.vars.id }}">
+    <div id="field_container_{{ id }}">
         {% if sonata_admin.field_description.options.edit == 'list' %}
         {% if sonata_admin.field_description.options.edit == 'list' %}
-            <span id="field_widget_{{ form.vars.id }}" >
+            <span id="field_widget_{{ id }}" >
                 {% if sonata_admin.field_description.associationadmin.id(sonata_admin.value) %}
                 {% if sonata_admin.field_description.associationadmin.id(sonata_admin.value) %}
                     {% render 'SonataAdminBundle:Helper:getShortObjectDescription' with {}, {
                     {% render 'SonataAdminBundle:Helper:getShortObjectDescription' with {}, {
                         'query': {
                         'query': {
                             'code':     sonata_admin.field_description.associationadmin.code,
                             'code':     sonata_admin.field_description.associationadmin.code,
-                            'objectId': sonata_admin.admin.id(sonata_admin.value),
+                            'objectId': sonata_admin.field_description.associationadmin.id(sonata_admin.value),
                             'uniqid':   sonata_admin.field_description.associationadmin.uniqid
                             'uniqid':   sonata_admin.field_description.associationadmin.uniqid
                         }
                         }
                     }%}
                     }%}
@@ -33,15 +33,15 @@ file that was distributed with this source code.
                 {{ form_widget(form) }}
                 {{ form_widget(form) }}
             </span>
             </span>
         {% else %}
         {% else %}
-            <span id="field_widget_{{ form.vars.id }}" >
+            <span id="field_widget_{{ id }}" >
                 {{ form_widget(form) }}
                 {{ form_widget(form) }}
             </span>
             </span>
         {% endif %}
         {% endif %}
-        <span id="field_actions_{{ form.vars.id }}" >
+        <span id="field_actions_{{ id }}" >
 
 
             {% if sonata_admin.field_description.options.edit == 'list' %}
             {% if sonata_admin.field_description.options.edit == 'list' %}
                 <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('list') }}"
                 <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('list') }}"
-                    onclick="start_field_dialog_form_list_{{ form.vars.id }}(event)"
+                    onclick="start_field_dialog_form_list_{{ id }}(event)"
                     class="sonata-ba-action"
                     class="sonata-ba-action"
                     style="{% if not sonata_admin.field_description.associationadmin.isGranted('LIST') %}display:none{% endif %}"
                     style="{% if not sonata_admin.field_description.associationadmin.isGranted('LIST') %}display:none{% endif %}"
                     >
                     >
@@ -53,7 +53,7 @@ file that was distributed with this source code.
             {% endif %}
             {% endif %}
 
 
             <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
             <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('create') }}"
-                onclick="start_field_dialog_form_add_{{ form.vars.id }}(event)"
+                onclick="start_field_dialog_form_add_{{ id }}(event)"
                 class="sonata-ba-action"
                 class="sonata-ba-action"
                 style="{% if not sonata_admin.field_description.associationadmin.isGranted('CREATE')%}display:none{% endif %}"
                 style="{% if not sonata_admin.field_description.associationadmin.isGranted('CREATE')%}display:none{% endif %}"
                 >
                 >
@@ -64,7 +64,7 @@ file that was distributed with this source code.
             </a>
             </a>
         </span>
         </span>
 
 
-        <div class="container sonata-ba-modal sonata-ba-modal-edit-one-to-one" style="display: none" id="field_dialog_{{ form.vars.id }}">
+        <div class="container sonata-ba-modal sonata-ba-modal-edit-one-to-one" style="display: none" id="field_dialog_{{ id }}">
 
 
         </div>
         </div>
     </div>
     </div>

+ 11 - 6
Resources/views/Form/admin_fields.html.twig

@@ -68,30 +68,35 @@ file that was distributed with this source code.
         TODO : improve this part
         TODO : improve this part
     #}
     #}
     {% if sonata_admin.field_description.mappingtype == 2 %}
     {% if sonata_admin.field_description.mappingtype == 2 %}
+        w-o-t-o
         {{ block('sonata_admin_orm_one_to_one_widget') }}
         {{ block('sonata_admin_orm_one_to_one_widget') }}
+
     {% elseif sonata_admin.field_description.mappingtype == 8 %}
     {% elseif sonata_admin.field_description.mappingtype == 8 %}
+        w-m-t-m
         {{ block('sonata_admin_orm_many_to_many_widget') }}
         {{ block('sonata_admin_orm_many_to_many_widget') }}
     {% elseif sonata_admin.field_description.mappingtype == 4 %}
     {% elseif sonata_admin.field_description.mappingtype == 4 %}
+        w-o-t-m
         {{ block('sonata_admin_orm_one_to_many_widget') }}
         {{ block('sonata_admin_orm_one_to_many_widget') }}
     {% endif %}
     {% endif %}
-
 {% endblock %}
 {% endblock %}
 
 
 {% block sonata_type_admin_widget %}
 {% block sonata_type_admin_widget %}
     {% if sonata_admin.field_description.mappingtype == 2 %}
     {% if sonata_admin.field_description.mappingtype == 2 %}
+        a-o-t-o
         {{ block('sonata_admin_orm_one_to_one_widget') }}
         {{ block('sonata_admin_orm_one_to_one_widget') }}
     {% elseif sonata_admin.field_description.mappingtype == 8 %}
     {% elseif sonata_admin.field_description.mappingtype == 8 %}
+        a-m-t-m
         {{ block('sonata_admin_orm_many_to_many_widget') }}
         {{ block('sonata_admin_orm_many_to_many_widget') }}
     {% elseif sonata_admin.field_description.mappingtype == 4 %}
     {% elseif sonata_admin.field_description.mappingtype == 4 %}
-        sonata_type_admin_widget
-
+        a-o-t-m
         {{ block('sonata_admin_orm_one_to_many_widget') }}
         {{ block('sonata_admin_orm_one_to_many_widget') }}
     {% endif %}
     {% endif %}
 {% endblock %}
 {% endblock %}
 
 
-{% block sonata_type_admin_collection_widget %}
+{% block sonata_type_collection_widget %}
     sonata_type_admin_collection_widget
     sonata_type_admin_collection_widget
-   {% if sonata_admin.field_description.mappingtype == 4 %}
+    {% if sonata_admin.field_description.mappingtype == 4 %}
+        c-o-t-m
         {{ block('sonata_admin_orm_one_to_many_widget') }}
         {{ block('sonata_admin_orm_one_to_many_widget') }}
-   {% endif %}
+    {% endif %}
 {% endblock %}
 {% endblock %}