【问题标题】:Why am I not getting my own page - drupal hook_menu为什么我没有自己的页面 - drupal hook_menu
【发布时间】:2011-01-04 20:56:26
【问题描述】:

我正在创建一个模块,其目的是导入特定类型的数据并根据该数据将其附加到节点。

为此,我需要创建一个页面,让用户输入数据的存储位置以供系统导入。

为此,我连接到 hook_menu 以创建如下页面:

function lbar_image_importer_menu(){
    $items = array();
    $items[] = array(
        'path' => "admin/content/lbar_image_importer",
        'title' => "Import LBar Images",
        'description' => "Innitiate an importation of LBar images from a ZIP file.",
        'page callback' => 'drupal_get_form',
    );
    return $items;
}

我通过挂钩到 hook_form_alter 函数来填充它将使用的表单,如下所示:

function lbar_image_importer_form_alter(&$form, &$form_state, $form_id) {   
    $form['admin']['lbar_zip_loc'] = array(
        '#type' => 'textfield',
        '#title' => 'Location of LBar Zip file: ',
        '#description' => 'This is where one or many of the lbar zip files are located. If this is a file, it will access only that zip file. If it is a directory it will open all zip files in that directory.',
    );
    $form['admin']['submit'] = array(
        "#type" => "submit",
        "#value" => "Import",
        '#submit' => array('lbar_image_importer_submit'),
    );

    return $form;
}

但是,我没有运气。它将我的表单元素附加到搜索表单,并重新显示管理/内容页面。我如何才能拥有自己的页面,例如 admin/content/node?​​p>

【问题讨论】:

    标签: drupal hook-menu hook-form-alter


    【解决方案1】:

    两件事。首先,路径应该在项目的数组键中。其次,没有访问参数或访问回调,您总是会被拒绝访问。阅读文档并遵循示例可能会对您有所帮助。

    function lbar_image_importer_menu(){
        $items = array();
        $items['admin/content/lbar_image_importer'] = array(
            'title' => "Import LBar Images",
            'description' => "Innitiate an importation of LBar images from a ZIP file.",
            'page callback' => 'drupal_get_form',
            'access callback' => true,
        );
        return $items;
    }
    

    如果没有page arguments 值,drupal_get_form 也不会做任何事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多