I have enabled a form under modules but accessing the page gives "page not found" error.
sites/default/modules/awesome_form/awesome_form.module
function awesome_form_menu(){
$items['my-new-form'] = array(
'title' => 'simple form',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('show_form_callback'),
'access arguments' => array('access content'),
'file' => 'application_file.inc'
);
return $items;
}
sites/default/modules/awesome_form/application_file.inc
function show_form_callback($form, &$form_state){
$form['test_input'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#title' => 'Name'
);
return $form;
}
sites/default/modules/awesome_form/awesome_form.info
name = Awesome Form
description = Some Test Form
core = 7.x
and when I browse to mysite.com/my-new-form I get "page not found" error. I also have enabled the module "Awesome Form" under modules. Yet same issue.
Related
For my drupal website, in my custom module (hr_payroll.module) I have the following to add URL handlers:
function hr_payroll_menu() {
$items['hr/payroll/employee/hours/overtime'] = array(
'title' => 'Overtime Submission',
'page callback' => 'hr_payroll_page',
'page arguments' => array('employee','hours','overtime'),
'access arguments' => array('access hr payroll'),
'type' => MENU_CALLBACK,
);
$items['hr/payroll'] = array(
'title' => 'Payroll',
'page callback' => 'hr_payroll_intro',
'access arguments' => array('access hr payroll'),
'type' => MENU_CALLBACK,
);
return $items;
}
On my site is a block that simply contains
echo(drupal_get_title());
If I go the URL hr/payroll, it shows the title 'Payroll'
BUT if I go to the URL hr/payroll/employee/hours/overtime it still shows 'Payroll' instead of the expected 'Overtime Submission'
So what am I totally misunderstanding about how the $title element of the menu item or the function drupal_get_title() work?
I believe you are using the hook_menu in the wrong way based on what you want to do.
First menu
$items['hr/payroll/employee/hours/overtime'] = array(
'title' => 'Overtime Submission',
'page callback' => 'hr_payroll_page',
'page arguments' => array('employee','hours','overtime'),
'access arguments' => array('access hr payroll'),
'type' => MENU_CALLBACK,
);
Are the arguments 'employee' 'hours' 'overtime' are static or they are dynamic ?? , and I see that page arguments supplied are the same ('employee','hours','overtime')
If they are dynamic use wildcard instead like
$items['hr/payroll/%/%/%'] = array(
'title' => 'Overtime Submission',
'page callback' => 'hr_payroll_page',
'page arguments' => array(2,3,4),
'access arguments' => array('access hr payroll'),
'type' => MENU_CALLBACK,
);
If the menu link "hr/payroll/employee/hours/overtime" is static , that means you don't need the access arguments provided as u already know what these values are on your page callback function.
And also why are you using type as MENU_CALLBACK.Is that by reason or by just random??
How to add a module link to main menu, beside the home tab, in drupal 7/8? here is my code
<?php
function api_manager_menu() {
$items = array();
$items['api_manager'] = array(
'title' => 'API Manager',
'description' => 'Manage the lifecycle of an API',
'page callback' => 'drupal_get_form',
'page arguments' => array('api_manager_form'),
'access arguments' => user_access('administer users'),
'type' => MENU_NORMAL_ITEM
);
return $items;
}
You just need to set the menu_name:
$items['api_manager'] = array(
'title' => 'API Manager',
'description' => 'Manage the lifecycle of an API',
'page callback' => 'drupal_get_form',
'page arguments' => array('api_manager_form'),
'access arguments' => user_access('administer users'),
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'primary-links'
);
See the hook_menu() docs for more information.
I hope you can help me because I don't know how to call a node in a hook_menu in Drupal 7.
Is it possible ?
$items['basketfacile/planning'] = array(
'type' => MENU_LOCAL_TASK,
'title' => 'Test',
'description' => "description",
'page callback' => 'drupal_get_form',
'page arguments' => array('basketfacile_plannings_form'),
'access arguments' => array('access content')
);
This is my item menu who call a form, but I want to call a node form which allready exists in my Drupal installation. We can take Article for example.
Have you an idea ?
In fact, it's very easy to embed a node in an other page you can do that :
$items['menu/submenu'] = array(
'type' => MENU_LOCAL_TASK,
'title' => 'YOUR_TITLE',
'description' => "YOUR_DESCRIPTION",
'page callback' => 'node_add',
'page arguments' => array('YOUR_NODE_TYPE_NAME_MACHINE'),
'access callback' => 'node_access',
'access arguments' => array('create', 'YOUR_NODE_TYPE_NAME_MACHINE'),
'file' => 'node.pages.inc',
'file path' => drupal_get_path('module', 'node')
);
How can I add a tab into my personal profile (/users/my-name)?
I used this function, but nothuing shows up:
function tpzclassified_menu() {
$items['user/%user/kleinanzeigen'] = array(
'title' => t('Meine Kleinanzeigen'),
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
You're missing the page callback property:
function tpzclassified_menu() {
$items['user/%user/kleinanzeigen'] = array(
'title' => t('Meine Kleinanzeigen'),
'page callback' => 'tpzclassified_kleinanzeigen',
'page arguments' => array(1),
'access callback' => 'user_view_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function tpzclassified_kleinanzeigen($account) {
return 'This is the Meine Kleinanzeigen page';
}
Replace tpzclassified_kleinanzeigen with the function name that generates the page.
Also, never use 'access callback' => TRUE: it's a huge security hole. I've changed that to use user_view_access(), which checks to the see if the user is allowed to view %user's profile. You could use user_edit_access() if you wanted to check to see if a user is allowed to edit %user's profile.
I upgraded a module from 5 to 6. I only have one problem:
I can access the settings page for it, but can not see the contents of it.
This is my code:
function agbnagscreen_menu() {
global $user;
$items = array();
if (agbnagscreen_nag($user)) {
// var_dump($_GET['q']); die();
drupal_goto(sprintf('%s/%s', AGBNAGSCREEN_NAGURL, base64_encode($_GET['q'])));
die();
}
$items['admin/settings/agbnagscreen'] = array(
// 'path' => 'admin/settings/agbnagscreen',
'title' => 'AGB nagscreen',
'access callback' => user_access('Einstellungen von AGB aendern'),
//'access' => user_access('Einstellungen von AGB aendern'),
'page callback' => 'drupal_get_form',
'callback arguments' => array('agbnagscreen_settings_fapi'),
);
$items[AGBNAGSCREEN_NAGURL] = array(
// 'path' => AGBNAGSCREEN_NAGURL,
'title' => 'Allgemeine Geschaeftsbedingungen',
'access' => TRUE,
'callback' => 'drupal_get_form',
'callback arguments' => array('agbnagscreen_fapi'),
'type' => MENU_SUGGESTED_ITEM,
);
return $items;
}
I think the problem is cause by this line:
'page callback' => 'drupal_get_form',
Is that correct? How can I write it, that it works?
You might want to read through the Drupal menu system (Drupal 6.x) handbook page to understand the changes to the menu system: you have several problems in your hook_menu implementation.
The conditional at the top will never fire: Drupal 6 only calls hook_menu() when the menu is rebuilt, not on every page load.
There is no callback: use page callback.
The page callback accepts page arguments, not callback arguments.
There is access: use access callback.
access callback always a string containing the function name, not a function, and defaults to "user_access": you need to supply access arguments.
A modified version of your hook_menu implementation might be:
function agbnagscreen_menu() {
$items = array();
$items['admin/settings/agbnagscreen'] = array(
'title' => 'AGB nagscreen',
'access arguments' => array('Einstellungen von AGB aendern'),
'page callback' => 'drupal_get_form',
'page arguments' => array('agbnagscreen_settings_fapi'),
);
$items[AGBNAGSCREEN_NAGURL] = array(
'title' => 'Allgemeine Geschaeftsbedingungen',
'access arguments' => array('access content'),
'page callback' => 'drupal_get_form',
'page arguments' => array('agbnagscreen_fapi'),
'type' => MENU_SUGGESTED_ITEM,
);
return $items;
}