Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal Menu Specifics

Submitted by on July 9, 2014 – 8:31 amNo Comment

Continuing articles devoted to menu in Drupal: its structure, functions, constants and specifics.

Drupal show tabs if there are 2 or more tabs. One tab won’t be shown.

4 level of depth are supported. For example:

function example_module_menu() {
$items[‘node/%/forum/%node’] = array(
‘title’ => ‘forum’,
‘page callback’ => ‘example_module_forum_form’,
‘page arguments’ => array(1, 3),
‘access callback’ => ‘example_module_forum_access’,
‘access arguments’ => array(1),
‘type’ => MENU_LOCAL_TASK,
‘file’ => ‘example_module.pages.inc’,
‘weight’ => 7
);
return $items;
}

Here, path is  ‘node/%/forum/%node’, where

  • node – null level (isn’t shown in tabs)
  • % – first level (isn’t shown in tabs)
  • forum – second level (tabs of the first level)
  • %node – third level (tabs of the second level)

Page title :  you can’t set or change title of a page for second-level tabs because the tabs follows one of the first-level tabs.

To change page title for the second-level tabs, you should do something like this:

/**
* Title callback.
*/
function example_module_page_title($node) {
if ((arg(3) == ‘node’ || arg(3) == ‘edit’) && is_numeric(arg(4))) {
$topic = node_load(arg(4));
drupal_set_title($topic->title);
} else{
drupal_set_title($node->title .’ ‘ . t(‘forum’));
}
return t(‘forum’);
}
function example_module_menu() {
$items[‘node/%node/forum’] = array(
‘title callback’ => ‘example_module_page_title’,
‘title arguments’ => array(1),
‘page callback’ => ‘example_module_forum_form’,
‘page arguments’ => array(1, 3),
‘access callback’ => TRUE,
‘type’ => MENU_LOCAL_TASK,
‘weight’ => 7,
);
$items[‘node/%node/forum/list’] = array(
‘title’ => ‘forum List’,
‘type’ => MENU_DEFAULT_LOCAL_TASK,
‘weight’ => -20,
);
$items[‘node/%node/forum/node/add’] = array(
‘title’ => ‘Create Discussion’,
‘page callback’ => ‘drupal_get_form’,
‘page arguments’ => array(‘example_module_node_form_reuse’),
‘access callback’ => ‘node_access’,
‘access arguments’ => array(‘create’, ‘forum’),
‘file’ => ‘node.pages.inc’,
‘file path’ => drupal_get_path(‘module’, ‘node’),
‘type’ => MENU_LOCAL_TASK,
‘weight’ => 10,
);
$items[‘node/%/forum/node/%node’] = array(
‘title’ => ‘View Discussion’,
// the next 2 lines aren’t used:
//’title callback’ => ‘example_module_topic_page_title’,
//’title arguments’ => array(1, 4),
‘page callback’ => ‘node_page_view’,
‘page arguments’ => array(4),
‘access callback’ => ‘node_access’,
‘access arguments’ => array(‘view’, 4),
‘type’ => MENU_LOCAL_TASK,
‘file’ => ‘node.pages.inc’,
‘file path’ => drupal_get_path(‘module’, ‘node’),
‘weight’ => -10,
);
$items[‘node/%/forum/edit/%node’] = array(
‘title’ => ‘Edit Discussion’,
‘page callback’ => ‘node_page_edit’,
‘page arguments’ => array(4),
‘access callback’ => ‘node_access’,
‘access arguments’ => array(‘update’, 4),
‘weight’ => 1,
‘file’ => ‘node.pages.inc’,
‘file path’ => drupal_get_path(‘module’, ‘node’),
‘type’ => MENU_LOCAL_TASK,
);
return $items;
}

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.