diff --git a/docs/index.rst b/docs/index.rst index 8168a032c..a7ecdd02e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -18,6 +18,7 @@ The ``Doctrine ORM Admin`` provides services to work with the ``Admin Bundle`` a reference/templates reference/audit reference/query_proxy + reference/data_source reference/troubleshootings .. toctree:: diff --git a/docs/reference/data_source.rst b/docs/reference/data_source.rst new file mode 100644 index 000000000..1d7763f9e --- /dev/null +++ b/docs/reference/data_source.rst @@ -0,0 +1,52 @@ +.. index:: + double: Reference; Export / DataSource + +Export / DataSource +=================== + +When using an admins export feature you might want to modify how dates and times are exported. +This is done by calling ``setDateTimeFormat`` on the data source iterator. + +Here's one way to do it: + +1. Decorate the default Sonata\DoctrineORMAdminBundle\Exporter\DataSource with your own and call ``setDateTimeFormat`` there.:: + + dataSource = $dataSource; + } + + public function createIterator(ProxyQueryInterface $query, array $fields): SourceIteratorInterface + { + /** @var DoctrineORMQuerySourceIterator $iterator */ + $iterator = $this->dataSource->createIterator($query, $fields); + + $iterator->setDateTimeFormat('Y-m-d H:i:s'); + + return $iterator; + } + } + + +2. Add the your service in the ``config/services.yaml`` definition.:: + + services: + ... + App\Service\Admin\DecoratingDataSource: + decorates: 'sonata.admin.data_source.orm' + +