Browse Source

Ask admin exporter service for available formats

Grégoire Paris 8 years ago
parent
commit
b80ab524aa

+ 3 - 0
Controller/CRUDController.php

@@ -110,6 +110,9 @@ class CRUDController extends Controller
             'form' => $formView,
             'form' => $formView,
             'datagrid' => $datagrid,
             'datagrid' => $datagrid,
             'csrf_token' => $this->getCsrfToken('sonata.batch'),
             'csrf_token' => $this->getCsrfToken('sonata.batch'),
+            'export_formats' => $this->has('sonata.admin.admin_exporter') ?
+                $this->get('sonata.admin.admin_exporter')->getAvailableFormats($this->admin) :
+                $this->admin->getExportFormats(),
         ), null);
         ), null);
     }
     }
 
 

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

@@ -176,8 +176,11 @@ file that was distributed with this source code.
                                 </div>
                                 </div>
 
 
 
 
+                                {# NEXT_MAJOR : remove this assignment #}
+                                {% set export_formats = export_formats|default(admin.exportFormats) %}
+
                                 <div class="pull-right">
                                 <div class="pull-right">
-                                    {% if admin.hasRoute('export') and admin.isGranted('EXPORT') and admin.getExportFormats()|length %}
+                                    {% if admin.hasRoute('export') and admin.isGranted('EXPORT') and export_formats|length %}
                                         <div class="btn-group">
                                         <div class="btn-group">
                                             <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                             <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                 <i class="fa fa-share-square-o" aria-hidden="true"></i>
                                                 <i class="fa fa-share-square-o" aria-hidden="true"></i>
@@ -185,7 +188,7 @@ file that was distributed with this source code.
                                                 <span class="caret"></span>
                                                 <span class="caret"></span>
                                             </button>
                                             </button>
                                             <ul class="dropdown-menu">
                                             <ul class="dropdown-menu">
-                                                {% for format in admin.getExportFormats() %}
+                                                {% for format in export_formats %}
                                                 <li>
                                                 <li>
                                                     <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">
                                                     <a href="{{ admin.generateUrl('export', admin.modelmanager.paginationparameters(admin.datagrid, 0) + {'format' : format}) }}">
                                                         <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                                         <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>

+ 5 - 1
Resources/views/CRUD/list_outer_rows_mosaic.html.twig

@@ -50,8 +50,12 @@ This template can be customized to match your needs. You should only extends the
                                 {% endblock %}
                                 {% endblock %}
                             </div>
                             </div>
                         </div>
                         </div>
+
+                        {# NEXT_MAJOR : remove this assignment #}
+                        {% set export_formats = export_formats|default(admin.getExportFormats) %}
+
                         <div class="mosaic-inner-text">
                         <div class="mosaic-inner-text">
-                            {% if (admin.hasRoute('batch') and batchactions|length > 0) or (admin.hasRoute('export') and admin.isGranted("EXPORT") and admin.getExportFormats()|length) %}
+                            {% if (admin.hasRoute('batch') and batchactions|length > 0) or (admin.hasRoute('export') and admin.isGranted("EXPORT") and export_formats|length) %}
                                 <input type="checkbox" name="idx[]" value="{{ admin.id(object) }}">
                                 <input type="checkbox" name="idx[]" value="{{ admin.id(object) }}">
                             {% else %}
                             {% else %}
                                 &nbsp;
                                 &nbsp;