Andrej Hudec 13 anni fa
parent
commit
59bd52a052

+ 6 - 0
Controller/CRUDController.php

@@ -542,6 +542,12 @@ class CRUDController extends Controller
     {
         $format = $request->get('format');
 
+        $allowedExportFormats = (array) $this->admin->getExportFormats();
+
+        if(!in_array($format, $allowedExportFormats) ) {
+            throw new \RuntimeException(sprintf('Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`', $format, $this->admin->getClass(), implode(', ', $allowedExportFormats)));
+        }
+
         $filename = sprintf('export_%s_%s.%s',
             strtolower(substr($this->admin->getClass(), strripos($this->admin->getClass(), '\\') + 1)),
             date('Y_m_d_H_i_s', strtotime('now')),

+ 9 - 5
Resources/views/CRUD/base_list.html.twig

@@ -74,11 +74,15 @@ file that was distributed with this source code.
                 {% block table_footer %}
                     <tr>
                         <th colspan="{{ admin.list.elements|length - (app.request.isXmlHttpRequest ? 2 : 1) }}">
-                            {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }} -
-                            {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
-                            {% for format in admin.getExportFormats() %}
-                                <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last%},{% endif %}
-                            {% endfor %}
+                            {{ admin.datagrid.pager.page }} / {{ admin.datagrid.pager.lastpage }}
+
+                            {% if admin.getExportFormats()|length > 0 %}
+                                -
+                                {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
+                                {% for format in admin.getExportFormats() %}
+                                    <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">{{ format }}</a>{% if not loop.last%},{% endif %}
+                                {% endfor %}
+                            {% endif %}
                         </th>
 
                         <th>