表单权限不适用于具有多个表单的模块

时间:2015-01-18 16:31:36

标签: forms module user-permissions

这在具有单个表单的模块中非常有用,但是在具有多个表单的模块中,表单不会显示在权限列表中。对于具有多种形式的模块,我需要做些什么?例如,在为每个表单识别模块中的任何表单之前,是否需要为每个表单添加安全性?

我将它添加到钩子菜单:

'access callback' => 'user_access',
'access arguments' => array('Spring Grove Scorecard Access'),

然后使用此功能:

function form_scorecard_permission() {
    return array(
       'Spring Grove Scorecard Access' => array(
       'title' => t('Spring Grove Scorecard Access'),
       'description' => t('Allows users to access the Spring Grove Scorecard.'),
    ),
  );

1 个答案:

答案 0 :(得分:0)

这是我没有完全理解权限功能如何工作的错。我没有意识到只需要一个函数来容纳所有表单权限。以下代码非常有用。希望它能帮助那些不像我一样光明的人:

function glatfelter_supplier_action_register_menu() {
  $items = array();

  $items['sar_performance_form'] = array( 
    'title' => 'SAR Performance',
    'description' => 'SAR Performance Form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('sar_performance_form'),
    'access callback' => 'user_access',
    'access arguments' => array('QCA SAR Performance Form Access'),
  );

    $items['sar_sdr_form'] = array( 
    'title' => 'SAR SDR/NCR',
    'description' => 'SAR SDR Form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('sar_sdr_form'),
    'access callback' => 'user_access',
    'access arguments' => array('QCA SAR SDR Form Access'),
  );

  return $items;
}

//***PEFORMANCE FORM***
function sar_performance_form($form, &$form_state) {

   //Display the overview
   $form['fs_sar_performance_overview'] = array(
     '#type' => 'fieldset',
     '#title' => t('Overview'),
   );

   $form['fs_sar_performance_overview']['sar_performance_overview'] = array(
     '#markup' => t('Performance form overview goes here'),
   );

   //Display the form
   $form['sar_performance_something'] = array(
     '#markup' => 'Form input can start here',
   );

   return $form;
}

//***SDR FORM***
function sar_sdr_form($form, &$form_state) {

   //Display the overview
   $form['fs_sar_sdr_overview'] = array(
     '#type' => 'fieldset',
     '#title' => t('Overview'),
   );

   $form['fs_sar_sdr_overview']['sar_sdr_overview'] = array(
     '#markup' => t('SDR form overview goes here'),
   );

   //Display the form
   $form['sar_sdr_something'] = array(
     '#markup' => 'Form input can start here',
   );

   return $form;
}

//This function adds the forms to the permissions menu
function glatfelter_supplier_action_register_permission() {
    return array(
       'QCA SAR Performance Form Access' => array(
       'title' => t('QCA SAR Performance Form Access'),
       'description' => t('Allows users to access the SAR Performance form.'),
       ),

       'QCA SAR SDR Form Access' => array(
       'title' => t('QCA SAR SDR Form Access'),
       'description' => t('Allows users to access the SAR SDR form.'),
       ),

    );
}