Procházet zdrojové kódy

Inverse merge order of persistent parameters in list editables (#4250)

Prevents overwriting parameters set in template. For example classification-bundle introduce context parameter which conflicts with context == 'list' expected by setObjectFieldValueAction()
Dariusz Markowicz před 8 roky
rodič
revize
b776d7d27a

+ 9 - 1
Resources/views/CRUD/base_list_field.html.twig

@@ -40,7 +40,15 @@ file that was distributed with this source code.
         {% set xEditableType = field_description.type|sonata_xeditable_type %}
         {% set xEditableType = field_description.type|sonata_xeditable_type %}
 
 
         {% if isEditable and xEditableType %}
         {% if isEditable and xEditableType %}
-            {% set url = path('sonata_admin_set_object_field_value', { 'context': 'list', 'field': field_description.name, 'objectId': admin.id(object), 'code': admin.code(object) }|merge(admin.getPersistentParameters|default([])) )  %}
+            {% set url = path(
+                'sonata_admin_set_object_field_value',
+                admin.getPersistentParameters|default([])|merge({
+                    'context': 'list',
+                    'field': field_description.name,
+                    'objectId': admin.id(object),
+                    'code': admin.code(object)
+                })
+            ) %}
             <span {% block field_span_attributes %}class="x-editable" data-type="{{ xEditableType }}" data-value="{{ field_description.type == 'date' and value is not empty ? value.format('Y-m-d') : value }}" data-title="{{ field_description.label|trans({}, field_description.translationDomain) }}" data-pk="{{ admin.id(object) }}" data-url="{{ url }}" {% endblock %}>
             <span {% block field_span_attributes %}class="x-editable" data-type="{{ xEditableType }}" data-value="{{ field_description.type == 'date' and value is not empty ? value.format('Y-m-d') : value }}" data-title="{{ field_description.label|trans({}, field_description.translationDomain) }}" data-pk="{{ admin.id(object) }}" data-url="{{ url }}" {% endblock %}>
                 {{ block('field') }}
                 {{ block('field') }}
             </span>
             </span>

+ 4 - 0
Tests/Twig/Extension/SonataAdminExtensionTest.php

@@ -228,6 +228,10 @@ class SonataAdminExtensionTest extends \PHPUnit_Framework_TestCase
      */
      */
     public function testRenderListElement($expected, $type, $value, array $options)
     public function testRenderListElement($expected, $type, $value, array $options)
     {
     {
+        $this->admin->expects($this->any())
+            ->method('getPersistentParameters')
+            ->will($this->returnValue(array('context' => 'foo')));
+
         $this->admin->expects($this->any())
         $this->admin->expects($this->any())
             ->method('isGranted')
             ->method('isGranted')
             ->will($this->returnValue(true));
             ->will($this->returnValue(true));