2

So, I am fairly new to Drupal (about 8 months in) and I am using Profile2 with 3 different profile types. Everything is working excellent, except for I wish I could wrap my head around how I can override the Profile2 view button when you click on, let's say Main Profile. So, if you are familiar with profile2, you know that it comes with a default profile as soon as it's activated, and when you click on it within the User Menu, you are presented with a screen with the local menu tabs called View, and Edit.

All I want to do is keep the View button, but change the path to either a panel page or an actual Views page.

I've explored hook_menu(), hook_menu_alter(), hook_menu_link_alter(), and to tell you the truth, I just don't get how those work. I believe hook_menu actually adds new "nodes" or paths to the system with their own page?

I think I have a lot to learn when it comes to these three functions (hook_menu(), hook_menu_alter(), and hook_menu_link_alter()) I just need a savior to explain these to me.

As a sub question, along with the View, and Edit button, how would I go about adding an extra local menu button to this row? Like upgrade my account, or view your bill?

Any light would be appreciated, and I do have the Devel module installed, as well as the theme developer tool. I tried making a custom module, and running a DPM on those functions above, but it's not even outputting anything.

3

hook_menu() -> Define menu items and page callbacks.

hook_menu_alter() -> Alter the data being saved to the {menu_router} table after hook_menu is invoked.

hook_menu_link_alter() -> Alter the data being saved to the {menu_links} table

0

To get result from those functions you will have to clear your caches. Use the admin_menu module which has a direct link for clearing caches.

There are a lot of examples available on how to use hook_menu. This is a comprehensive step step example: How should I implement hook_menu()? or another example on how to create tabs: create tabs with hook_menu() for custom module

  • Which part of the question is this answer answering. – kiamlaluno Feb 26 '13 at 11:11
  • I think this is clear. I explain why he does not see results when he uses dpm() I also give him proper references for his subquestion (how would I go about adding an extra local menu button to this row?) The other reference is an answer to his request for 'any light'. – Mike Feb 26 '13 at 11:25
0

I was investigating this more and finally came to a solution on how to add a local task menu to a profile2 page. It's kind of dirty, but it will do for now.

I basically added this to my site's glue module to modify the local task items.

function ch_glue_menu_local_tasks_alter(&$data, $router_item, $root_path) {
global $user;

foreach($user->roles as $k=>$v){
    if(preg_match('/paid1|paid2|paid3/i', $v)){
        $is_paid_member = true;
    }
}

if(preg_match('/profile/i', $root_path) && !$is_paid_member){
        // Add a tab linking to node/add to all pages.
        $data['tabs'][0]['output'][] = array(
            '#theme' => 'menu_local_task',
            '#link' => array(
                'title' => t('Upgrade Account'),
                'href' => 'node/3',
                'localized_options' => array(
                    'attributes' => array(
                        'title' => t('Add new content'),
                    ),
                ),
            ),
        );
}
}

Thanks for explaining the menu functions, but it seems like I have A LOT to learn when it comes to the drupal menu system. I'm just glad this will work for right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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