Parcourir la source

Get default formats from the exporter

Grégoire Paris il y a 8 ans
Parent
commit
f31dea1a13
3 fichiers modifiés avec 9 ajouts et 2 suppressions
  1. 2 0
      Admin/AbstractAdmin.php
  2. 5 1
      Controller/CRUDController.php
  3. 2 1
      composer.json

+ 2 - 0
Admin/AbstractAdmin.php

@@ -555,6 +555,8 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface
 
     /**
      * {@inheritdoc}
+     *
+     * NEXT_MAJOR: return null to indicate no override
      */
     public function getExportFormats()
     {

+ 5 - 1
Controller/CRUDController.php

@@ -800,6 +800,10 @@ class CRUDController extends Controller
         $format = $request->get('format');
 
         $allowedExportFormats = (array) $this->admin->getExportFormats();
+        // NEXT_MAJOR: simplify this condition
+        if ($allowedExportFormats == array('json', 'xml', 'csv', 'xls') && $this->has('sonata.exporter.exporter')) {
+            $allowedExportFormats = $this->get('sonata.exporter.exporter')->getAvailableFormats();
+        }
 
         if (!in_array($format, $allowedExportFormats)) {
             throw new \RuntimeException(
@@ -819,7 +823,7 @@ class CRUDController extends Controller
             $format
         );
 
-        // NEXT_MAJOR : require sonata-project/exporter ^1.6 and remove this
+        // NEXT_MAJOR : require sonata-project/exporter ^1.7 and remove this
         $exporter = $this->has('sonata.exporter.exporter') ?
             $this->get('sonata.exporter.exporter') :
             $this->get('sonata.admin.exporter');

+ 2 - 1
composer.json

@@ -52,7 +52,8 @@
         "symfony/yaml": "^2.3 || ^3.0"
     },
     "conflict": {
-        "jms/di-extra-bundle": "<1.7.0"
+        "jms/di-extra-bundle": "<1.7.0",
+        "sonata-project/exporter": "1.6.0"
     },
     "suggest": {
         "jms/di-extra-bundle": "Annotations for Admin definition",