Skip to content

Commit

Permalink
Add AbstractAdmin::configureExportFields extension point (#6348)
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Sep 7, 2020
1 parent 57ee852 commit 8146671
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/reference/action_export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ 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 ``getExportFields()`` method::
behavior for a specific admin, you can override the ``configureExportFields()`` method::

public function getExportFields()
protected function configureExportFields(): array
{
return ['givenName', 'familyName', 'contact.phone', 'getAddress'];
}
Expand Down
12 changes: 11 additions & 1 deletion src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,13 @@ public function getExportFormats()
}

/**
* @final since sonata-project/admin-bundle 3.x
*
* @return array
*/
public function getExportFields()
{
$fields = $this->getModelManager()->getExportFields($this->getClass());
$fields = $this->configureExportFields();

foreach ($this->getExtensions() as $extension) {
if (method_exists($extension, 'configureExportFields')) {
Expand Down Expand Up @@ -3259,6 +3261,14 @@ public function canAccessObject($action, $object)
return $this->hasAccess($action, $object);
}

/**
* @return string[]
*/
protected function configureExportFields(): array
{
return $this->getModelManager()->getExportFields($this->getClass());
}

protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
{
return $query;
Expand Down

0 comments on commit 8146671

Please sign in to comment.