문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top