为什么我没有获得自己的页面 - drupal hook_menu

发布于 2024-10-10 11:56:14 字数 1286 浏览 7 评论 0原文

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

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

为此,我连接到 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?

I have a module I'm creating and its purpose is to import a specific type of data and append it to nodes depending on that data.

To do this, I need to create a page letting the user enter where the data is stored at for the system to import.

To do this, I'm hooking into hook_menu to create the page like this:

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;
}

I populate the form that it will use by hooking into the hook_form_alter function like thus:

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;
}

However, I am having no luck. It appends my form elements to the search form, and redisplays the admin/content page. How can I make it so I have my own page, like admin/content/node?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-10-17 11:56:14

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

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;
}

如果没有页面参数值,drupal_get_form也不会执行任何操作。

Two things. First, the path should be in the array key for the item. Second, without either access arguments or an access callback, you'll always get access denied. Reading the docs and following the examples may help you here.

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;
}

drupal_get_form isn't going to do anything without a page arguments value, either.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文