1
我在我的應用程序上使用了Sonata管理員,並且想要根據用戶權限創建或編輯實體時禁用某些選項卡。到目前爲止,我已經嘗試在選項卡上添加一個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();