Prechádzať zdrojové kódy

Add multidimensional arrays support in show array template (#4567)

Emmanuel Vella 7 rokov pred
rodič
commit
dbdaee3a92

+ 23 - 0
Resources/views/CRUD/base_array_macro.html.twig

@@ -0,0 +1,23 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+{% macro render_array(value, inline) %}
+    {% for key, val in value %}
+        {% if val is iterable %}
+            [{{ key }} => {{ _self.render_array(val, inline) }}]
+        {%  else %}
+            [{{ key }} => {{ val }}]
+        {%  endif %}
+
+        {% if not loop.last and not inline %}
+            <br>
+        {% endif %}
+    {% endfor %}
+{% endmacro %}

+ 2 - 11
Resources/views/CRUD/list_array.html.twig

@@ -8,19 +8,10 @@ For the full copyright and license information, please view the LICENSE
 file that was distributed with this source code.
 
 #}
-{% import _self as list %}
-{%  macro render_array(value) %}
-    {% for key, val in value %}
-        {% if val is iterable %}
-            [{{ key }} => {{ list.render_array(val) }}}]
-        {%  else %}
-            [{{ key }} => {{ val }}]
-        {%  endif %}
-    {% endfor %}
-{% endmacro %}
+{% import 'SonataAdminBundle:CRUD:base_array_macro.html.twig' as list %}
 
 {% extends admin.getTemplate('base_list_field') %}
 
 {% block field %}
-    {{ list.render_array(value) }}
+    {{ list.render_array(value, field_description.options.inline is not defined or field_description.options.inline) }}
 {% endblock %}

+ 2 - 11
Resources/views/CRUD/show_array.html.twig

@@ -8,19 +8,10 @@ For the full copyright and license information, please view the LICENSE
 file that was distributed with this source code.
 
 #}
+{% import 'SonataAdminBundle:CRUD:base_array_macro.html.twig' as show %}
 
 {% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}
 
 {% block field%}
-    {% for key, val in value %}
-        {% if field_description.options.safe %}
-            [{{ key }} => {{ val|raw }}]
-        {% else %}
-            [{{ key }} => {{ val }}]
-        {% endif %}
-
-        {% if not loop.last %}
-            {% if field_description.options.inline is not defined or false == field_description.options.inline %}<br>{% endif %}
-        {% endif %}
-    {% endfor %}
+    {{ show.render_array(value, field_description.options.inline|default(false)) }}
 {% endblock %}