Skip to content

Commit

Permalink
Use admin exporter service when available
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Aug 17, 2016
1 parent 358597e commit 206bf9d
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,28 @@ public function exportAction(Request $request)

$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 (!$this->has('sonata.admin.admin_exporter')) {
// NEXT_MAJOR: remove this block
@trigger_error(
'Not registering the exporter bundle is deprecated since version 3.x.'
.' You must register it to be able to use the export action in 4.0.',
E_USER_DEPRECATED
);
$allowedExportFormats = (array) $this->admin->getExportFormats();

$class = $this->admin->getClass();
$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')),
$format
);
$exporter = $this->get('sonata.admin.exporter');
} else {
$adminExporter = $this->get('sonata.admin.admin_exporter');
$allowedExportFormats = $adminExporter->getAvailableFormats($this->admin);
$filename = $adminExporter->getExportFilename($this->admin, $format);
$exporter = $this->get('sonata.exporter.exporter');
}

if (!in_array($format, $allowedExportFormats)) {
Expand All @@ -828,18 +846,6 @@ public function exportAction(Request $request)
);
}

$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')),
$format
);

// 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');

return $exporter->getResponse(
$format,
$filename,
Expand Down

0 comments on commit 206bf9d

Please sign in to comment.