I've posted this 3 times already and cannot seem to see the post don't know what I am doing wrong.
I've created my batch action my my admin class as below:
namespace ACME\MyBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Route\RouteCollection;
class JournalistProfileAdmin extends Admin
{
...........
...........
public function getBatchActions()
{
$lists = $this->getModelManager()->createQuery('ACME\MyBundle\Entity\ContactList', 'c')->execute();
$listsArray = array();
foreach ($lists as $list)
{
$listsArray[$list->getId()] = $list->getName();
}
$actions = parent::getBatchActions();
$actions['addToGroup'] = array(
'label' => $this->trans('action_add_to_group', array(), 'SonataAdminBundle'),
'ask_confirmation' => true,
'secondary' => $listsArray,
);
return $actions;
}
}
Then extended the CRUDController as in the file below:
namespace ACME\MyBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery as ProxyQueryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
class JournalistProfileAdminController extends Controller
{
public function batchActionAddToIsRelevant()
{
return true;
}
public function batchActionAddToGroup(ProxyQueryInterface $selectedModelQuery)
{
........................
...........................
}
When I try to run my batch action, I get Sonata\AdminBundle\Controller\CRUDController::batchActionAddToGroup method must be created error.
Can anyone please help?
I think you forgot to specify your JournalistProfileAdminController in your service declaration. I just had this problem. The service declaration should look like this (in Services.yml):
what.ever.JournalistProfileAdmin:
class: your\classpath\Admin\JournalistProfileAdmin
arguments: [ null, your\Bundle\Entity\JournalistProfile, 'YourBundle:Admin\JournalistProfileAdmin' ]
calls:
- [...]
tags:
- [...]
Here the last argument is important. It should not be SonataAdminBundle:CRUD but YourBundle:JournalistProfileAdmin
Your question is pretty old, but I hope this will help someone one day.
Well, in your second code snippet, you have a batchActionGroup method. This needs to be called batchActionAddToGroup instead (because, in the first code snippet, you are calling your new batch action 'add to group' not 'group'). I hope that helps
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