1

I am creating a module in Drupal 7. The module is working well now, but I doesn't create an admin menu link.

I used the following code:

<?php
function question_mark_menu() {
    $items = array();

    $items['admin/question-mark'] = array(
        'title' => 'Question mark',
        'description' => 'Manage your question mark',
        'page callback' => 'question_mark_page',
        'access arguments' => array('administer question mark'),
        'type' => MENU_NORMAL_ITEM,
    );
    return $items;
}
?>

I tried to clear my cache but nothing works.

What is wrong in my code?

  • 1
    Hello and welcome to Drupal Answers! What do you expect the code to do? – kiamlaluno May 25 '15 at 13:02
  • Thanks for you comment. It creates a menu item in the configuration menu. – Noname May 25 '15 at 13:05
  • Have you given your user the 'administer question mark' permission? – rooby May 25 '15 at 13:05
  • Do you mean it DOESN'T create a menu item in the configuration menu? – kiamlaluno May 25 '15 at 13:15
  • Oh, yes, I'm sorry. – Noname May 25 '15 at 13:17
1

The path for the configuration menu is at admin/config, so try this:

function question_mark_menu() {
  $items = array();

  $items['admin/config/question-mark'] = array(
    'title' => 'Question mark',
    'description' => 'Manage your question mark',
    'page callback' => 'question_mark_page',
    'access arguments' => array('administer question mark'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

Also, make sure your user has the 'administer question mark' permission that you have specified.

|improve this answer|||||
  • This is not working for me. What do you mean with the permissions? – Noname May 25 '15 at 13:21
  • 1
    Well you're specifying that you need the 'administer question mark' permission to access that page so only users with that permission (or user 1) will be able to see the menu item. – rooby May 25 '15 at 13:27
  • I can do this with the hook_permission, right? – Noname May 25 '15 at 13:31
  • 1
    You define the permission with hook_permission() then you assign that permission to user roles on the permissions administration screen. – rooby May 25 '15 at 13:39
  • Rooby might be right about what the real problem is, but why not first use any of the "existing" permissions (just to test). That way you don't have to worry for now about the hook_permission (that could become the next part of solving your issue then). It's like "how to eat an elephant?" ... Answer: 1 bite (not byte ...) at a time ... – Pierre.Vriens May 25 '15 at 13:48

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