How to call a node in a hook menu? - drupal

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

Related

How to make custom module menu selected in drupal 7

I have created a custom module in drupal 7 which shows a navigation menu in admin menu bar , but when I click on it it is not selected . Here is the menu hook
function tableof_content_menu() {
$items['admin/tableof_content/add'] = array(
'title' => t('Add TOC'),
'page callback' => 'drupal_get_form',
'page arguments' => array('tableof_content_admin_add_form'),
//'access callback' => TRUE,
'access arguments' => array('administer my module'),
'type' => MENU_NORMAL_ITEM
);
$items['admin/tableof_content/edit/%'] = array(
'title' => 'Edit TOC',
'page callback' => 'drupal_get_form',
'page arguments' => array('tableof_content_admin_add_form',3),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
$items['admin/tableof_content/search/%'] = array(
'title' => 'Add TOC',
'page callback' => 'drupal_get_form',
'page arguments' => array('tableof_content_admin_add_form',3),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
}
Also I have checked with firebug and in other menu the class "active-trail" is showing which is not appearing in my menu .
Thanks for your help in advance
Maybe you could do the trick dynamically in each node_view. You get the current node path with $path = menu_get_active_trail() and you set the menu item as active with menu_set_active_item($path). I had to do that once.

Drupal: Issue with hook_menu

I trying to add a link like this :
$items['channel/%'] = array(
'title' => t('channel'),
'page callback' => 'ptt_get_channel_list',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
but when I add this link, I have no access to adming/config menu.
I have several link like this :
$items['ptt/items'] = array(
'title' => t('channel'),
'page callback' => 'ptt_get_items',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['ptt/items/detail'] = array(
'title' => t('channel'),
'page callback' => 'ptt_get_items_details',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
Now when I add one more link, I can't access adming/config. Why?

Drupal Custom Module returning wrong title

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 in drupal?

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.

Drupal: How to display a menu item of access denied and redirect it to login page

I am using drupal 7 and entity_registration module ( registration-7.x-1.0-alpha5) for event registration.
There the register link is displayed for the specific role only i.e. if permission is set for authenticated user, them the register link is displayed to the authenticated users.
If we try to manually visit the page for example node/9/register it shows access denied.
Now, I have using LoginToboggan redirected access denied page to user login page. But when I manually create a menu item Named Register having path node/9/register, the menu item itself is not displaying.
I want a way to tell users to login to register or something like that..
I hope you got my point.
Here is the module file code.. I think there is some problem in formatting so I have pasted just hook_menu and hook_permission functions..please visit the link for viewing full code www.karyashala.in/code.html
/**
* Implements hook_menu().
*/
function registration_menu() {
$items['registration/%registration'] = array(
'title callback' => 'registration_page_title',
'title arguments' => array(1),
'page callback' => 'registration_view',
'page arguments' => array(1),
'access callback' => 'entity_access',
'access arguments' => array('view', 'registration', 1),
);
$items['registration/%registration/view'] = array(
'title' => 'View',
'page callback' => 'registration_view',
'page arguments' => array(1),
'access callback' => 'entity_access',
'access arguments' => array('view', 'registration', 1),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['registration/%registration/edit'] = array(
'title' => 'Edit',
'page callback' => 'drupal_get_form',
'page arguments' => array('registration_form', 1),
'access callback' => 'entity_access',
'access arguments' => array('update', 'registration', 1),
'weight' => 10,
'type' => MENU_LOCAL_TASK,
);
$items['registration/%registration/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('registration_delete_confirm', 1),
'access callback' => 'entity_access',
'access arguments' => array('delete', 'registration', 1),
'type' => MENU_CALLBACK,
);
// entity local tasks
foreach (registration_get_registration_instances() as $instance) {
$type = $instance['entity_type'];
if (!in_array($type, array('registration', 'registration_type'))) {
$items[$type . '/%entity_object/register'] = array(
'load arguments' => array($type),
'title' => 'Register',
'page callback' => 'registration_register_page',
'page arguments' => array(0, 1),
'access callback' => 'registration_register_page_access',
'access arguments' => array(0, 1),
'type' => MENU_LOCAL_TASK,
);
$items[$type . '/%entity_object/registrations'] = array(
'load arguments' => array($type),
'title' => 'Manage Registrations',
'page callback' => 'registration_registrations_page',
'page arguments' => array(0, 1),
'access callback' =>
'registration_administer_registrations_access',
'access arguments' => array(0, 1),
'type' => MENU_LOCAL_TASK,
);
$items[$type . '/%entity_object/registrations/list'] = array(
'load arguments' => array($type),
'title' => 'Registrations',
'page callback' => 'registration_registrations_page',
'page arguments' => array(0, 1),
'access callback' => 'registration_administer_registrations_access',
'access arguments' => array(0, 1),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[$type . '/%entity_object/registrations/settings'] = array(
'load arguments' => array($type),
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('registration_registrations_settings_form', 0,
1),
'access callback' => 'registration_administer_registrations_access',
'access arguments' => array(0, 1),
'weight' => 9,
'type' => MENU_LOCAL_TASK,
);
$items[$type . '/%entity_object/registrations/broadcast'] = array(
'load arguments' => array($type),
'title' => 'Email Registrants',
'page callback' => 'drupal_get_form',
'page arguments' => array('registration_registrations_broadcast_form', 0,
1),
'access callback' => 'registration_administer_registrations_access',
'access arguments' => array(0, 1),
'weight' => 10,
'type' => MENU_LOCAL_TASK,
);
}
}
if (module_exists('devel')) {
$items['registration/%registration/devel'] = array(
'title' => 'Devel',
'page callback' => 'devel_load_object',
'page arguments' => array('node', 1),
'access arguments' => array('access devel information'),
'type' => MENU_LOCAL_TASK,
'file path' => drupal_get_path('module', 'devel'),
'file' => 'devel.pages.inc',
'weight' => 100,
);
$items['registration/%registration/devel/load'] = array(
'title' => 'Load',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
}
return $items;
}
/**
* Implements hook_permission().
*/
function registration_permission() {
$permissions = array(
'administer registration types' => array(
'title' => t('Administer registration types'),
'description' => t('Manage registration types, fields, and display
settings.'),
'restrict access' => TRUE,
),
'administer registration' => array(
'title' => t('Administer registration'),
'description' => t('View, edit, delete, and manage all registrations,
regardless of type.'),
'restrict access' => TRUE,
),
);
foreach(registration_get_types() as $type_info) {
$permissions += registration_permission_list($type_info);
}
return $permissions;
}
Add the line after + sign and clear cache after that check it again.
function registration_menu() {
$items['registration/%registration'] = array(
'title callback' => 'registration_page_title',
'title arguments' => array(1),
'page callback' => 'registration_view',
'page arguments' => array(1),
'access callback' => 'entity_access',
'access arguments' => array('view', 'registration', 1),
+ 'type' => MENU_NORMAL_ITEM,
);

Resources