27

I'm working on a module in Drupal 7. I've added a hook_menu implementation:

$items['admin/config/content/mymodule'] = [
  'title'            => 'MyModule',
  'description'      => 'Configure MyModule settings.',
  'page callback'    => 'mymodule_get_form',
  'page arguments'   => ['mymodule_admin_settings'],
  'file'             => 'mymodule.admin.inc',
  'access arguments' => ['administer mymodule'],
  'menu_name'        => 'mymodule',
];

...and a configure line to mymodule.info:

configure = admin/config/content/mymodule

A Configure link for MyModule now appears the admin/modules page, but how can I also have the module listed on the admin/config page? Or is the admin/config page reserved for only core modules?

9

Looking at the code of system_admin_config_page(), which is page callback for admin/config, I notice it contains the following lines:

if ($admin = db_query("SELECT menu_name, mlid FROM {menu_links} WHERE link_path = 'admin/config' AND module = 'system'")->fetchAssoc()) {
  $result = db_query("
    SELECT m.*, ml.*
    FROM {menu_links} ml
    INNER JOIN {menu_router} m ON ml.router_path = m.path
    WHERE ml.link_path != 'admin/help' AND menu_name = :menu_name AND ml.plid = :mlid AND hidden = 0", $admin, array('fetch' => PDO::FETCH_ASSOC));
  foreach ($result as $item) {
    _menu_link_translate($item);
    if (!$item['access']) {
      continue;
    }
    // ...
  }
  // ...
}

The first query select the menu_name field for the menu associated with the path admin/config, which by default is management; the second query select all the menus that have the same value for menu_name, and whose parent is admin/config.

As your menu uses a different value for menu_name, it is not selected from the second query, and it is not show in the admin/config page.

24

If you do it like this, with the system.module callback for the parent item, you get the nice listing page when you visit 'admin/config/mymodule'

/**
 * Implements hook_menu().
 */
function MYMODULE_menu() {

  $items = [];

  $items['admin/config/mymodule'] = [
    'title'            => 'My configuration section',
    'description'      => 'This is the parent item',
    'position'         => 'left',
    'weight'           => -100,
    'page callback'    => 'system_admin_menu_block_page',
    'access arguments' => ['administer site configuration'],
    'file'             => 'system.admin.inc',
    'file path'        => drupal_get_path('module', 'system'),
  ];

  // Need at least one child item before your section will appear.
  $items['admin/config/mymodule/item'] = [
    'title'            => 'First item',
    'description'      => 'This is the first child item in the section',
    'page callback'    => 'mymodule_item_callback',
    'access arguments' => ['administer site configuration'],
  ];

  return $items;
}
  • 3
    Don't forget that you'll need to disable and enable the module for the menu changes to take effect. – jevon May 30 '13 at 2:02
  • 5
    @jevon: clearing the (menu) cache is adequate to see the changes. – Bart Dec 10 '13 at 9:19
  • menu cache can be cleared using drush at command line using drush cc menu - ref: drupal.stackexchange.com/a/58621/1082 – therobyouknow Jun 28 '17 at 7:41
3

Remove the 'menu_name' part, that is not necessary.

1

I had trouble with this too on the config page. The only way I was able to do add the link to the config page was to declare two menu items like so, with the parent link at 'admin/config/module' and a child link at 'admin/config/module/manage'.

  $items['admin/config/whh-maps'] = array(
    'title' => 'World Hiphop configuration',
    'description' => 'Allows administrators to configure maps for WHH.',
    'position' => 'left',
    'weight' => -30,
    'page callback' => 'drupal_get_form',
    'page arguments' => array('whh_maps_form'),
    'access arguments' => array('administer whh maps'),
    'file' => 'whh_maps.admin.inc',
  );
  $items['admin/config/whh-maps/manage'] = array(
    'title' => 'Manage countries',
    'description' => 'Allows admins to edit country information',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('whh_maps_form'),
    'access arguments' => array('administer whh maps'),
    'file' => 'whh_maps.admin.inc',
    'weight' => -10,
  ); 
1
$items['admin/config/user-interface/mymodule'] = array(
    'title' => 'My Module',
    'description' => 'description',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('my_admin_function'),
    'access arguments' => array('administer site configuration'),
);

$items['admin/config/user-interface/mymodule/manage'] = array(
    'title' => 'My Module',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'description' => 'description',
    'weight' => -10,
);
return $items;

this worked for me.
I was actually struggling for about half an hour until I realized I wasn't returning $items....I always seem to do that.

0
/**
 * Implements hook_menu().
 */
function notification_menu() {

  $items = [];

  $items['admin/customize'] = [
    'title'            => 'Send Comment notifications',
    'discription'      => 'Admin will send notification to user about updates',
    'type'             => MENU_NORMAL_ITEM,
    'page callback'    => 'drupal_get_form',
    'page arguments'   => ['notification_form'],
    'access arguments' => ['access adminstration page'],
    'access callback'  => TRUE,
  ];

  return $items;
}

/**
 * Custom form.
 */
function notification_form($form, &$form_state) {

  $form['send_mail_to'] = [
    '#title'         => 'Send Mail To',
    '#discription'   => 'To whom you want to send form',
    '#size'          => 40,
    '#type'          => 'textfield',
    '#required'      => TRUE,
    '#default_value' => variable_get('send_mail_to'),
  ];

  //here the admin can wite subject for the mail.
  $form['mail_subject'] = [
    '#title'         => 'Subject',
    '#discription'   => 'the purpous of this mail',
    '#type'          => 'textfield',
    '#size'          => 40,
    '#maxlenght'     => 120,
    '#required'      => TRUE,
    '#default_value' => variable_get('mail_subject'),
  ];

  $form['mail_body'] = [
    '#title'         => 'Body',
    '#discription'   => 'the body of your mail.',
    '#type'          => 'textarea',
    '#row'           => 10,
    '#columns'       => 40,
    '#required'      => TRUE,
    '#default_value' => variable_get('mail_body'),
  ];

  $form['mail_bcc'] = [
    '#title' => 'BCC this mail to all',
    '#type'  => 'checkbox',

  ];

  return system_settings_form($form);
}
  • 1
    This doesn't answer the question, since it doesn't say why the OP is not seeing their module listed in the admin page; plus, code-only answers are not much helpful. (Check the code: You have some typos.) – kiamlaluno Jan 28 '15 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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