PHPackages                             heimrichhannot/contao-exporter-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. heimrichhannot/contao-exporter-bundle

ActiveContao-bundle[PDF &amp; Document Generation](/categories/documents)

heimrichhannot/contao-exporter-bundle
=====================================

A backend module for exporting any contao entity to file.

0.11.6(2y ago)13.3k2[5 issues](https://github.com/heimrichhannot/contao-exporter-bundle/issues)[2 PRs](https://github.com/heimrichhannot/contao-exporter-bundle/pulls)2LGPL-3.0-or-laterPHPPHP ^7.4 || ^8.0

Since Jul 25Pushed 2y ago5 watchersCompare

[ Source](https://github.com/heimrichhannot/contao-exporter-bundle)[ Packagist](https://packagist.org/packages/heimrichhannot/contao-exporter-bundle)[ Docs](https://github.com/heimrichhannot/contao-exporter-bundle)[ RSS](/packages/heimrichhannot-contao-exporter-bundle/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (15)Versions (34)Used By (2)

Contao Exporter Bundle
======================

[](#contao-exporter-bundle)

A module for exporting any contao entity to file.

[![Contao Exporter Bundle Backend Config Preview](docs/img/screenshot.png)](docs/img/screenshot.png)

*Export config preview*

Features
--------

[](#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)
    - pdf
    - Media files (export media files assoziated with an entity as archive(zip))

Csv and Excel export are archived by [Spout library](https://github.com/box/spout). PDF export is archived by [mPDF library](https://github.com/mpdf/mpdf). This library comes not as dependency and therefore must be added to your bundle/project dependencies to archvie pdf export functionality.

Technical instruction
---------------------

[](#technical-instruction)

### Install

[](#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

[](#backend-export)

#### Step 1

[](#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

[](#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

[](#step-3)

Create a configuration for your export by using the exporter's backend module (group devtools).

### Frontend

[](#frontend)

You can use the included frontend module to add an easy export functionality.

You can also use [frontendedit](https://github.com/heimrichhannot/contao-frontendedit) or [formhybrid\_list](https://github.com/heimrichhannot/contao-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:

1. Create a configuration for your export by using the exporter's backend module (group devtools).
2. Call `export()` of `huh.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
----------

[](#developers)

### Upgrade from exporter module

[](#upgrade-from-exporter-module)

Please see [Upgrade Instructions](UPGRADE.md).

### Events

[](#events)

You can hook into the export with given event. Please check [Symfony Event Documentation](https://symfony.com/doc/3.4/event_dispatcher.html) if you don't know how.

EventnameEvent-IDDescriptionBefore Exporthuh.exporter.event.before\_exportFired before start of export. Customize file name and file path.Before Build Queryhuh.exporter.event.before\_build\_queryFired before building and executing the query for collecting list content.Modify Table Header fieldhuh.exporter.event.modifyheaderfieldsModify header field values in tables.Modify Table field valuehuh.exporter.event.modifyfieldvalueFired before writing a table value to the table object (e.g. spreadsheet).Modify Media File Namehuh.exporter.event.modifymediafilenameModify media file before adding to archive (filename and file object).### Add custom exporter

[](#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

[](#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:

1. A list of field names. Example: `['firstname','lastname','age']`
2. A field list with labels and values. Should be structured as shown:

```
