【问题标题】:Form Permissions not working in Module with Multiple Forms表单权限在具有多个表单的模块中不起作用
【发布时间】:2015-01-18 16:31:35
【问题描述】:

这在具有单个表单的模块中效果很好,但是在具有多个表单的模块中,该表单不会显示在权限列表中。对于具有多种形式的模块,我需要做些什么不同的事情吗?例如,我是否需要为每个表单添加安全性才能识别模块中的任何表单?

我将此添加到挂钩菜单中:

'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.'),
    ),
  );

【问题讨论】:

    标签: forms module user-permissions


    【解决方案1】:

    这是我的错,因为我没有完全理解权限功能的工作原理。我没有意识到只需要一个函数来容纳所有表单权限。以下代码效果很好。希望它能帮助像我一样不那么聪明的其他人:

    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.'),
           ),
    
        );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 2013-05-15
      相关资源
      最近更新 更多