sonata-project/SonataAdminBundle — pull request #714 by Romain-Geissler (2012-04-25 18:05:13+00:00)
Title: Introduce the batchActionXXXIsRelevant functions and use it if defined.

A added a commit upon the already merged PR #713.

As we can now use other request variable to perform custom batch action, we also have a more complex logic when it comes to accept a batch action or not. That's why i introduced the method ``batchActionXXXIsRelevant`` that should return either ``true`` (we can perform the action), ``false`` (we can't and the default information message will be used) or an information message (we can't perform the action, the error is explained by the message).

For example, i have the following ``merge`` action that uses the usual selected rows, a target row, and some selected sub rows (because each my row display a collection of sub models).

I use the following :

```php
public function batchActionMergeIsRelevant(array $normalizedSelectedIds,$allEntitiesSelected){
$parameterBag=$this->get('request')->request;

if(!$parameterBag->has('targetId')){
return 'flash_batch_no_target';
}

$normalizedTargetId=$parameterBag->get('targetId');

if($allEntitiesSelected){
return true;
}

$normalizedSelectedIds=array_filter($normalizedSelectedIds,function($normalizedSelectedId) use($normalizedTargetId){
return $normalizedSelectedId!==$normalizedTargetId;
});

$normalizedSelectedDocumentationOrderIds=$parameterBag->get('documentationOrderIds',[]);

return count($normalizedSelectedIds)+count($normalizedSelectedDocumentationOrderIds)>0;
}
```