[Solved] Add module to admin/config page in Drupal7

We are going to create a following custom block in admin/config page.
Drupal admin/config block - Configure Products

To create a block in admin/config like those ‘People, Content Authoring, Media’ etc. We need to define two menu items as shown below


function products_menu() {
$items = array();
$items['admin/config/products'] = array(
      'title' => 'Configure Products',
      'description' => 'Allows administrators to configure product items',
      'weight' => -30,
      'page callback' => 'drupal_get_form',
      'page arguments' => array('products_admin_settings_form'),
      'access arguments' => array('administer products'),
      'file' => 'products.admin.inc',
  );

  $items['admin/config/products/manage'] = array(
      'title' => 'Manage Products',
      'description' => 'Allows admins to manage products',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('products_admin_settings_form'),
      'access arguments' => array('administer products'),
      'file' => 'products.admin.inc',
      'weight' => -10,
  );

  return $items;
}

admin/config/products – highlighted above line no. 3

Creates a new block with title Configure Products

admin/config/products/manage – highlighted above line no. 13

This menu item is visible under the Configure Products as clickable item. When this link “Manage Products” is clicked, it invokes the ‘products_admin_settings_form’ page callback which eventually displays a form for products configuration.

If there is any confusions please post them on comment.

7 thoughts on “[Solved] Add module to admin/config page in Drupal7

    1. Samundra Shrestha

      In products.admin.inc I have function that generates the drupal forms using FORM API of drupal.

      The function callbacks is products_admin_settings_form, which is sent as argument to drupals internal function drupal_get_form, which takes form_id as argument and then in return it returns the rendered form to the path assigned to the menu.

      You can also see the function being defined as page arugments.

      Reply
      1. Giancarlo Diana

        Ok, it’s normal form then..
        infact i copy your code in my hook_menu and it works!

        I will find the error and i’ll report it here to the world 😀 …

        Reply
        1. Giancarlo Diana

          Ok Samundra,
          i understood…

          There wasn’t a MENU_NORMAL_ITEM item “son” of my path…
          i explain it better:

          to get a new block in admin/config page, is needed a MENU_NORMAL_ITEM like this:
          “admin/config/mylink”
          and a son like this:
          “admin/config/mylink/son”

          My fault was the using of MENU_LOCAL_TASK as son (because I needed it for other reasons)…

          thank you
          Giancarlo

Leave a Reply

Your email address will not be published. Required fields are marked *