Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating drupal 6 module with tabs

I'm creating a module that let's your users add feeds. So i want my code to provide tabs that can be overwritten at the theme layer.

I thought this could be done with the hook_menu:

$items['tab_add_feed'] = array(
  'title' => 'Add Feed',
  'page callback' => 'xml_parser_add_feed',
  'access callback' => 'user_access',
  'access arguments' => array('manage own feeds'),
  'type' => MENU_LOCAL_TASK,
);

something like the above. But I'm using it on the front side of the site.

How can i add tabs or links on top of my page the drupal way?

//edit

There are none tabs present at the moment, maybe i have to make them visible?

fixed it by adding <a href="xml_parser/add_feed">add feed</a> to the main page callback function But this is ugly, hard coded and not theme-able. waiting for a better solution.

//edit

This is the code i am using now

function xml_parser_menu() {
    $items = array();

    $items['xml_parser'] = array(
            'path' => 'xml_parser',
            'title' => t('Feed'),
            'description' => t('Add/edit feeds'),
            'page callback' => 'xml_parser_manage_overview', 
            'access callback' => 'user_access', // get user access
            'access arguments' => array('manage own feeds'), // check user if premission is set
            'type' => MENU_NORMAL_ITEM,
            'menu_name' => 'primary-links', // add to primary menu
    );

    $items['xml_parser/add_feed'] = array(
            'path' => 'xml_parser/add_feed',
            'title' => 'Add Feed',
            'page callback' => 'xml_parser_add_feed',
            'access callback' => 'user_access',
            'access arguments' => array('manage own feeds'),
            //'access' => user_access('maintain own subscriptions'),
            'type' => MENU_LOCAL_TASK,
    );
    return $items;
}
like image 566
FLY Avatar asked May 02 '26 10:05

FLY


1 Answers

I think the name of the item would be something like 'user/%/add_feed', with the % argument being the user id. Also, the access callback is spelled incorrectly, should be user_access. This should create a tab for a user on the user profile page. You could also do node/%/add_feed to add a tab to a node.

While developing this module, you may find it useful to also use this:

function mymodule_init() {
   cache_clear_all();
   menu_router_build();
}

Until you get the menu straight.

If you want to just add an arbitrary tab to a page to add a feed, it would probably be an autonomous menu or a themed link. I would need to know more about the context of the feeds you are trying to provide and how users are subscribing.

like image 126
Kevin Avatar answered May 05 '26 09:05

Kevin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!