symfony - Define Sonata Admin dynamically -
is possible define sonata admins dynamically? problem is, have n lists (or classifiers) want create admin for, , don't fancy idea create separate service every list.
example lists:
list_id item_id name country est estonia country lat latvia country ltu lithuania lang et estonian lang lv latvian ...etc
each list may have different requirements (different validation rules instance) , use default item admin, possibility override it.
or how it?
the quick way
you can add if-conditions in listmapper:
public function configurelistfields(listmapper $listmapper) { $listmapper ->add('id') // every entity has (for example) ; if ($condition) { ->add('country') // if $condition true } }
but dunno how imagine access admin. different roles/routes?
use multiple admins
a better approach creating abstractadmin (base)entity , extending use-cases (than can add every admin menue though). allow 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 1 (for example) } }
then extend 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 got entity-examples correct, should show how define baseadmin , extend multiple admins (allowing adding/removing fields , validation-groups per admin).
Comments
Post a Comment