heimrichhannot / contao-exporter-bundle
A backend module for exporting any contao entity to file.
Installs: 2 520
Dependents: 2
Suggesters: 1
Security: 0
Stars: 1
Watchers: 6
Forks: 2
Open Issues: 7
Type:contao-bundle
Requires
- php: ^7.4 || ^8.0
- box/spout: ^2.7
- contao/core-bundle: ^4.9
- heimrichhannot/contao-field-value-copier-bundle: ^1.1
- heimrichhannot/contao-multi-column-editor-bundle: ^1.2 | ^2.0
- heimrichhannot/contao-utils-bundle: ^2.207
- symfony/cache: ^4.4 || ^5.2
- symfony/config: ^4.4||^5.4
- symfony/console: ^4.4||^5.4
- symfony/dependency-injection: ^4.4||^5.4
- symfony/event-dispatcher: ^4.4||^5.4
- symfony/event-dispatcher-contracts: ^1||^2||^3
- symfony/http-foundation: ^4.4||^5.4
- symfony/http-kernel: ^4.4||^5.4
- symfony/translation: ^4.4||^5.4
- symfony/translation-contracts: ^1.1.6||^2||^3
Suggests
- mpdf/mpdf: ^7.0 for pdf export
Replaces
This package is auto-updated.
Last update: 2024-11-08 13:16:43 UTC
README
A module for exporting any contao entity to file.
Export config preview
Features
- export entities and list of entities
- easily add backend modules to your application/extension or use the frontendmodule
- expandable exporter architecture
- included exporter:
- csv
- Excel (xlsx)
- Media files (export media files assoziated with an entity as archive(zip))
Csv and Excel export are archived by Spout library. PDF export is archived by mPDF library. This library comes not as dependency and therefore must be added to your bundle/project dependencies to archvie pdf export functionality.
Technical instruction
Install
Install with composer:
composer require heimrichhannot/contao-exporter-bundle
If you want to use the pdf exporter, add "mpdf/mpdf":"^7.0"
to your composer dependencies.
Backend export
Step 1
Define your global operation in your entity's dca as follows:
'global_operations' => [ 'export_csv' => \Contao\System::getContainer()->get('huh.exporter.action.backendexport') ->getGlobalOperation('export_csv',$GLOBALS['TL_LANG']['MSC']['export_csv']) ],
Step 2
Add your backend module in your entity's config.php as follows:
$GLOBALS['BE_MOD']['mygroup']['name'] = [ 'export_csv' => ['huh.exporter.action.backendexport', 'export'], 'tables' => ['tl_name'], ];
Step 3
Create a configuration for your export by using the exporter's backend module (group devtools).
Frontend
You can use the included frontend module to add an easy export functionality.
You can also use frontendedit or formhybrid_list in order to easily create a module for manipulating your entities in the frontend. It already contains a function to export entities after submission!
You can also create an custom implementation for your extension:
- Create a configuration for your export by using the exporter's backend module (group devtools).
- Call
export()
ofhuh.exporter.action.frontendexport
service in your module:
/** @var Symfony\Component\DependencyInjection\ContainerInterface $container */ $container->get('huh.exporter.action.export')->export($config: ExporterModel, $entity: int|string, $fields = []: array);
Developers
Upgrade from exporter module
Please see Upgrade Instructions.
Events
You can hook into the export with given event. Please check Symfony Event Documentation if you don't know how.
Add custom exporter
You can add custom exporter to add additional file types or functionality.
Your exporter class must implement ExporterInterface
and must be registered in the container with the huh_exporter.exporter
service tag. We recommend to extend AbstractExporter
, because it already has most of the mechanics implemented.
services:
_defaults:
autowire: true
_instanceof:
HeimrichHannot\ContaoExporterBundle\Exporter\ExporterInterface:
tags: ['huh_exporter.exporter']
lazy: true
Your\Exporter\Class: ~
Custom field selection
You can pass an array of fields to export()
of an exporter. Those fields will be used, when exporting an item.
There are two options:
- A list of field names. Example:
['firstname','lastname','age']
- A field list with labels and values. Should be structured as shown:
<?php $fields = [ 'field1' => [ 'raw' => '', // raw field value 'inputType' => '', // field input type 'value' => '', // formatted field value 'formatted' => '', // formatted field value 'label' => '', // formatted field value ], // ... ];
To use Pdf export, you first need to install mPDF.
Templates
You can overwrite the pdf output template. Templates are written in Twig and name should start with exporter_pdf_
. See exporter_pdf_item_default.html.twig
for a working example.
Fonts
To add custom Pdf font, please see the corresponding chapters in Utils Bundle docs and the mPDF Docs. Afterwards you can add the folders in the exporter config.