The quick way
You can simply add if-conditions in your ListMapper:
public function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('id') // every Entity has this (for example)
;
if ($condition) {
->add('country') // only if $condition is true
}
}
But I dunno how you imagine to access you Admin. Different roles/routes?
Use multiple Admins
A better approach would be creating an AbstractAdmin for your (Base)Entity and extending it for your use-cases (than you can add every Admin to your menue though). This would also easily allow you overwriting
use Sonata\AdminBundle\Admin\AbstractAdmin;
abstract class BaseAdmin extends AbstractAdmin
{
/**
* default validation group
*
* @var array
*/
protected $formOptions = array(
'validation_groups' => array('default'),
);
public function configureListFields(ListMapper $listMapper)
{
$listMapper->add('id'); // every entity gets this one (for example)
}
}
Then just extend your admin:
class CountryAdmin extends BaseAdmin
{
protected $formOptions = array(
'validation_groups' => array('default', 'country'),
);
public function configureListFields(ListMapper $listMapper)
{
parent::configureListFields($listMapper);
$listMapper->add('country');
}
}
I'm not sure if I got your entity-examples correct, but it should show you how to define your BaseAdmin and extend multiple Admins (allowing adding/removing fields and validation-groups per Admin).
listIdproperty to differentiate the real admins withcreateQueryto separate each list. Thus, you have a whole admin for each list. - yceruto