Drupal Logo

[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
[sourcecode language=”php” highlight=”3,13″]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;
}

[/sourcecode]

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 Replies to “[Solved] Add module to admin/config page in Drupal7”

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

      1. 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 😀 …

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

Comments are closed.