我在我的应用程序上使用Sonata Admin,并希望在根据用户权限创建或编辑实体时禁用某些选项卡。到目前为止,我已经尝试在选项卡上添加一个css类,但在渲染时似乎被忽略了。这是我的代码:
protected function configureFormFields(FormMapper $formMapper)
{
$securityContext = $this->getConfigurationPool()->getContainer()->get('security.authorization_checker');
$em = $this->getConfigurationPool()->getContainer()->get('Doctrine')->getManager();
$arr = $em->getRepository('AppBundle:Staff')->findByDesignation(9);
$formMapper
->tab('1. Service Start Section')
->with('Brief Information')
->add('dateOfReceipt','sonata_type_datetime_picker', array('format'=>'dd/MM/yyyy HH:mm', 'dp_side_by_side' => false,'dp_use_current' => true))
->add('receiptMode','choice',['choices' => ['Email' => 'Email', 'Letter' => 'Letter', 'Orally / Meeting' => 'Orally / Meeting', 'Phone' => 'Phone']])
->add('client', 'sonata_type_model_list', array('btn_delete' => false))
->add('natureOfTheBrief',CKEditorType::class, array(
'config' => array(
'uiColor' => '#ffffff',
//...
)))
->add('forwardTo',StaffType::class,['label' => 'Forward To', 'choices' => $arr,'choice_value' => 'id'])
->end()
->end();
$disabled = $securityContext->isGranted('ROLE_PROFESSIONAL_SERVICES_MANAGER') ? '' : 'tab-disabled';
$formMapper
->tab('2. Service Commencement Section',array('class' => $disabled))
->with('Brief Analysis')
.....
.....
->end()
-end();
答案 0 :(得分:2)
当用户没有适当的权利时,根本不要添加标签:
protected function configureFormFields(FormMapper $formMapper)
{
$securityContext = $this->getConfigurationPool()->getContainer()->get('security.authorization_checker');
$em = $this->getConfigurationPool()->getContainer()->get('Doctrine')->getManager();
$arr = $em->getRepository('AppBundle:Staff')->findByDesignation(9);
$formMapper
->tab('1. Service Start Section')
->with('Brief Information')
->add('dateOfReceipt','sonata_type_datetime_picker', array('format'=>'dd/MM/yyyy HH:mm', 'dp_side_by_side' => false,'dp_use_current' => true))
->add('receiptMode','choice',['choices' => ['Email' => 'Email', 'Letter' => 'Letter', 'Orally / Meeting' => 'Orally / Meeting', 'Phone' => 'Phone']])
->add('client', 'sonata_type_model_list', array('btn_delete' => false))
->add('natureOfTheBrief',CKEditorType::class, array(
'config' => array(
'uiColor' => '#ffffff',
//...
)))
->add('forwardTo',StaffType::class,['label' => 'Forward To', 'choices' => $arr,'choice_value' => 'id'])
->end()
->end();
if($securityContext->isGranted('ROLE_PROFESSIONAL_SERVICES_MANAGER')){
$formMapper
->tab('2. Service Commencement Section',array('class' => $disabled))
->with('Brief Analysis')
.....
.....
->end()
->end();
}
答案 1 :(得分:0)
尝试一下:
$tabs = $this->getFormTabs();
unset($tabs['2. Service Commencement Section']);
$this->setFormTabs($tabs);