Maybe the question is too easy to answer, but I searched in the documentation of sonata admin bundle and i didn't find what I need. When you navigate to the List view of a model in sonata admin Bundle you find the Action Button in the upper right and under it you find the add new action. In my case I need that the Add new action to be displayed directly In the View Like in this screenshot :
Any one can help me please ?
I know this is an old question, but I'll leave this answer for future reference.
I had to do something similar, this is how I did it.
In your admin class override the configureActionButtons() method
class YourAdmin extends AbstractAdmin
{
//...
/**
* Overriden from (AbstractAdmin)
*/
public function configureActionButtons($action, $object = null)
{
$list = parent::configureActionButtons($action,$object);
$list['custom_action'] = array(
'template' => 'AcmeBundle:YourAdmin:custom_button.html.twig',
);
return $list;
}
//...
}
And then creating your button in AcmeBundle/Resources/views/YourAdmin/custom_button.html.twig
{# custom_button.html.twig #}
<a class="sonata-action-element" href="{{ admin.generateUrl('your_route') }}">
<i class="fa fa-plus-circle"></i>Custom Action
</a>
Of course you can add permissions check afterwards (they were omitted for clarity)
Hope it helps somebody
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With