[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.

Samundra Shrestha

I work as fullstack developer. Having spent more than 5 years in the web development technologies, I aspire to create an environment where we can share, learn and grow together.

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

  • September 18, 2012 at 10:09 AM
    Permalink

    What do you do in products.admin.inc?
    I tried with no result…
    it doesn’t work…

    Reply
    • September 18, 2012 at 10:20 AM
      Permalink

      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
      • September 18, 2012 at 10:32 AM
        Permalink

        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
        • September 18, 2012 at 10:39 AM
          Permalink

          Thanks for the information sharing. This will really help other people trying to get this working. :)

        • September 18, 2012 at 10:50 AM
          Permalink

          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

        • December 27, 2012 at 11:30 AM
          Permalink

          but still not clear

Leave a Reply

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