I have a transaction with numerous status codes. I want the user to be able to see these status codes as strings in SonataAdmin. The user should also be able to filter based on these status codes.
Entity Transaction { const TRANSACTION_STATUS_WAITING = 1; const TRANSACTION_STATUS_PENDING = 2; const TRANSACTION_STATUS_CONFIRMED = 3; public function setStatus($status) { $this->status = $status; } public function getStatus() { return $this->status; } public function getStatusAsString() { switch($this->status){ case(self::TRANSACTION_STATUS_WAITING): return "Waiting for Merchant"; case(self::TRANSACTION_STATUS_PENDING): return "Pending Confirmation"; case(self::TRANSACTION_STATUS_CONFIRMED): return "Confirmed"; } } }
I set up my list of sonata cards as follows:
protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('id') ->add('statusAsString', null, array('sortable' => true, 'label' => 'Status')) }
which works great:
However, I cannot use the same as the filter.
If I try this:
protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $datagridMapper ->add('user') ->add('status')
This does not work. It gives the following error →
Notice: Undefined index: statusAsString in ..../Sonata\DoctrineORMAdminBundle\Guesser\FilterTypeGuesser.php
How can I make it work?
source share