Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by SensioLabs
  1. Home
  2. Documentation
  3. Bundles
  4. SonataAdminBundle
  5. The Export action
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud

Table of Contents

  • Basic configuration
  • Routes
  • Translation
  • Picking which fields to export
  • Overriding the export formats for a specific admin
  • Customizing the query used to fetch the results

The Export action

Edit this page

The Export action

This document will cover the Export action and related configuration options.

Basic configuration

If you have registered the SonataExporterBundle bundle, you can benefit from a lot of flexibility:

  • You can configure default exporters globally.
  • You can add custom exporters, also globally.
  • You can configure every default writer.

See the exporter bundle documentation for more information.

Routes

You can disable exporting entities by removing the corresponding routes in your Admin. For more detailed information about routes, see Routing:

1
2
3
4
5
6
7
8
9
10
// src/Admin/PersonAdmin.php

final class PersonAdmin extends AbstractAdmin
{
    protected function configureRoutes(RouteCollectionInterface $collection): void
    {
        // Removing the export route will disable exporting entities.
        $collection->remove('export');
    }
}

Translation

All field names are translated by default. An internal mechanism checks if a field matching the translator strategy label exists in the current translation file and will use the field name as a fallback.

Picking which fields to export

By default, all fields are exported. More accurately, it depends on the persistence backend you are using, but for instance, the doctrine ORM backend exports all fields (associations are not exported). If you want to change this behavior for a specific admin, you can override the configureExportFields() method:

1
2
3
4
protected function configureExportFields(): array
{
    return ['givenName', 'familyName', 'contact.phone', 'getAddress'];
}

Note

Note that you can use contact.phone to access the phone property of `Contact` entity. Or use a getter if you have some virtual field.

You can also tweak the list by creating an admin extension that implements the configureExportFields() method:

1
2
3
4
5
6
public function configureExportFields(AdminInterface $admin, array $fields): array
{
    unset($fields['updatedAt']);

    return $fields;
}

Overriding the export formats for a specific admin

Changing the export formats can be done by defining a getExportFormats() method in your admin class:

1
2
3
4
public function getExportFormats(): array
{
    return ['pdf', 'html'];
}

Customizing the query used to fetch the results

If you want to customize the query used to fetch the results for a specific admin, you can override the DataSourceInterface class:

1
2
3
4
5
6
7
final class DataSource implements DataSourceInterface
{
    public function createIterator(ProxyQueryInterface $query, array $fields): \Iterator
    {
        // Custom implementation
    }
}

And then you can override the datasource set to the admin class.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    We stand with Ukraine.
    Version:
    Check Code Performance in Dev, Test, Staging & Production

    Check Code Performance in Dev, Test, Staging & Production

    Peruse our complete Symfony & PHP solutions catalog for your web development needs.

    Peruse our complete Symfony & PHP solutions catalog for your web development needs.

    Symfony footer

    ↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

    Avatar of Adriana Suurlant, a Symfony contributor

    Thanks Adriana Suurlant (@dsuurlant) for being a Symfony contributor

    2 commits • 9 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • Symfony at a Glance
      • Symfony Components
      • Case Studies
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • SymfonyConnect
      • Support
      • How to be Involved
      • Code of Conduct
      • Events & Meetups
      • Projects using Symfony
      • Downloads Stats
      • Contributors
      • Backers
    • Blog

      • Events & Meetups
      • A week of symfony
      • Case studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Documentation
      • Living on the edge
      • Releases
      • Security Advisories
      • SymfonyInsight
      • Twig
      • SensioLabs
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Deployed on

    Follow Symfony

    Search by Meilisearch