1

I am fairly new to Drupal and still figuring out its inner workings. Currently, I am playing around with creating own modules. I want to create a tabbed menu via hook_menu and display it. Unfortunately, I seem to fail here. I lack the understanding how to activate the coded menu in the hook on one of my pages. Since I do not define a block (and with such have no hook block_info or block_view in my module), I am not able to place my module via the structure menu anywhere. And by itself, the tabbed menu does not show up anywhere. My module is available in the modules' list and I can activate and deactivate it. I also cleared all caches, but I can't seem to find it anywhere. Hence, my question is: how do I activate and place the menu on my site?

My module has the two files dummy_module.module and dummy_module.info.

dummy_module.module:

/**
 * Implements hook_menu().
 */
function dummy_module_menu() {
  $items = array();
  $items['dummy'] = array(
    'title' => 'dummy_module',
    'page callback' => 'temp_output',
    'access callback' => TRUE,
    'weight' => 1
  );
  $items['dummy/new_tab1'] = array(
    'title' => 'Current 1',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'page callback' => 'temp_output1',
    'weight' => 2
  );
  $items['dummy/new_tab2'] = array(
    'title' => 'Current 2',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'temp_output2',
    'weight' => 3
  );

  return $items;
}


function temp_output() {
  return 'Hello world!';
}


function temp_output1() {
  return 'Hello world 1!';
}

function temp_output2() {
  return 'Hello world 2!';
}

dummy_module.info:

name = Dummy Module
description = This is a dummy module and hence the basis for all further module development.
core = 7.x
files[] = dummy_module.module
3

1 Answer 1

1

Alright, I found the problem: my tabs definitions were lacking the extra line

'access callback' => TRUE,

With this line in each tab definition, the tabs show up as extected. Here is my final code for dummy_module.module:

<?php

/**
 * Implements hook_menu().
 */
function dummy_module_menu() {
  $items = array();
  $items['dummy_module'] = array(
    'title' => 'dummy_module',
    'page callback' => 'temp_output',
    'access callback' => TRUE,
    'weight' => 30
  );
  $items['dummy_module/new_tab1'] = array(
    'title' => 'Current 1',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'page callback' => 'temp_output1',
    'access callback' => TRUE,
    'weight' => 1
  );
  $items['dummy_module/new_tab2'] = array(
    'title' => 'Current 2',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'temp_output2',
    'access callback' => TRUE,
    'weight' => 2
  );

  return $items;
}


function temp_output() {
  return 'Hello world!';
}


function temp_output1() {
  return 'Hello world 1!';
}

function temp_output2() {
  return 'Hello world 2!';
}
1
  • As a side-note, setting the access callback to TRUE means everyone will always be able to see this. It's generally better to omit access callback (defaults to "user_access()") and use 'access arguments' => array('access content') so that only users who can access content can see those items. If you give that permission to anonymous users (default) it's the same effect, but makes it easier to remove that access down the road without getting into the code and requiring a cache clear.
    – Alex Weber
    Commented Jan 15, 2014 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.