Reputation: 33
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.
Upvotes: 0
Views: 466
Reputation: 529
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 :)
Upvotes: 0
Reputation: 11
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
}
}
Upvotes: 1