The default flash message in Sonata admin bundle adds the key and value to the message:
Item "AppBundle\\Entity\\Users:00000000342d9b58000000004a2ab3f9" has been successfully created.
Could someone tell me how to get rid of the key and just have the value displayed? Thank you.
I believe there is an answer to this question on sonata project github. Try to add __toString($object) method to your Sonata Admin class:
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use App\Entity\Category;
class CategoryAdmin extends AbstractAdmin
{
public function toString($object)
{
return $object instanceof Category
? $object->getName()
: 'Category'; // shown in the breadcrumb on the create view
}
}
For example override flash_create_success -> (Item "%name%" has been successfully created.), you need to create SonataAdminBundle.en.xliff file in your SonataAdminBundle's child and after that insert into file:
<trans-unit id="flash_create_success">
<source>flash_create_success</source>
<target>WHAT DO YOU WANT TO SHOW.</target>
</trans-unit>
Clear cache and test :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.