How to add a module link to main menu in drupal? - 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.

Related

Page not found for Drupal form

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.

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?

How to call a node in a hook menu?

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

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