0

I am starting to write my first drupal module, but I need help on how to add content / text / data to the screen? I was able to add tabs and a url with hook menu, but I am unsure of how one goes about adding data you want to put there. If I wanted to say "hello world", what function / hook do I use to do that?

function sky_view_menu(){
    $items = [];
    $items['admin/skyview'] = array(
        'title' => 'Skyview Settings',
        'type' => MENU_NORMAL_ITEM,
        'access callback' => TRUE,
    );
    $items['admin/skyview/tab1'] = array(
        'title' => 'Skyview',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'access callback' => TRUE,
        'weight' => 0,
    );
    $items['admin/skyview/tab2'] = array(
        'title' => 'test1',
        'type' => MENU_LOCAL_TASK,
        'access callback' => TRUE,
        'weight' => 1,
    );
    $items['admin/skyview/tab3'] = array(
        'title' => 'test2',
        'type' => MENU_LOCAL_TASK,
        'access callback' => TRUE,
        'weight' => 2,
    );
    return $items;
}

1 Answer 1

1

You're looking for the page callback, which is:

The function to call to display a web page when the user visits the path. If omitted, the parent menu item's callback will be used instead.

For example:

function sky_view_menu() {
  $items['admin/skyview'] = array(
    'title' => 'Skyview Settings',
    'type' => MENU_NORMAL_ITEM,
    'access callback' => TRUE,
    'page callback' => 'MYMODULE_skyview_admin_page',
  );

  $items['admin/skyview/tab1'] = array(
    'title' => 'Skyview',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'access callback' => TRUE,
    'weight' => 0,
    'page callback' => 'MYMODULE_skyview_admin_tab_1',
  );
  ...
  return $items;
}

function MYMODULE_skyview_admin_page() {
  return [
    '#markup' => t('Hello world'),
  ];
}

function MYMODULE_skyview_admin_tab_1() {
  return [
    '#markup' => t('Hello tab 1'),
  ];
}

The function name itself is arbitrary, but for the sake of sanity it's best to name it as something that represents the route behind it.

1
  • This was the key element I was missing! Thank you so much! ^_^
    – Shawn
    Commented Oct 28, 2018 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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