Closed Nayden-TaylorAndHart closed 3 years ago
This is not a bug. The associated_property is a property path to retrieve the "string" representation of the collection element ; not a closure.
Thanks, Documentaion .associated_property (o): property path to retrieve the “string” representation of the collection element, or a closure with the element as argument and return a string.
I didn't look at the doc, I looked at the code: https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/BaseFieldDescription.php#L41
associated_property is used here: https://github.com/sonata-project/SonataAdminBundle/blob/57ee852cecaddb25b6502186c1cf84c13945d8f9/src/Datagrid/ListMapper.php#L98
I don't think it's possible to support a closure.
I'll update the doc ; thanks for the report !
np :)
Now I re-read this, the problem is about sorting, associated_property
admits a closure for visualizing the data, but you cannot sort by that (because it's a "calculated" field).
Now I re-read this, the problem is about sorting,
associated_property
admits a closure for visualizing the data, but you cannot sort by that (because it's a "calculated" field).
Then the sort should be disable, how is it decided if the column can be sorted or not ?
Environment
Sonata packages
Symfony packages
PHP version
Subject
Minimal repository with the bug
protected function configureListFields(ListMapper $listMapper) {
Steps to reproduce
Sort By Name
Expected results
To sort
Actual results
Crash with Object of class Closure could not be converted to string
`Error: Object of class Closure could not be converted to string
at /app/vendor/sonata-project/doctrine-orm-admin-bundle/src/Datagrid/ProxyQuery.php:233 at Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery->setSortBy(array(array('fieldName' => 'object1')), array('fieldName' => object(Closure))) (/app/vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:165) at Sonata\AdminBundle\Datagrid\Datagrid->buildPager() (/app/vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:292) at Sonata\AdminBundle\Datagrid\Datagrid->getForm() (/app/vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php:135) at Sonata\AdminBundle\Controller\CRUDController->listAction() (/app/vendor/symfony/http-kernel/HttpKernel.php:158) at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1) (/app/vendor/symfony/http-kernel/HttpKernel.php:80) at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true) (/app/vendor/symfony/http-kernel/Kernel.php:201) at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) (/app/public/index.php:83) `