0

So I want to have different menu links depending on if a user has received a message or not.

I make a hook_menu() instance, like this:

/**
 * Implements hook_menu().
 */
function MYMODULE_menu() {
  global $user;
  $items = array();
  $items['user/' . $user->uid . '/messages'] = array(
    'access callback' => 'user_is_logged_in',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'main-menu',
    'title' => t('Messages'),
  );
  return $items;
}

However it only takes me to my user page, and not the messages (which should be a view at the path specified).

Is there a way to make it so that I can directly go from this item link in the menu to the view?

0

Got it from here:

http://zufelt.ca/blog/embedding-view-menu-hook-drupal

Changed my hook instance to this:

/**
 * Implements hook_menu().
 */
function MYMODULE_menu() {
  global $user;
  $items = array();
  $items['user/' . $user->uid . '/messages'] = array(
    'access callback' => 'user_is_logged_in',
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'main-menu',
    'title' => t('Messages'),
    'page callback' => 'views_embed_view',
    'page arguments' => array('message_private', 'page_1'),
    'file path' => drupal_get_path('module', 'views'),
    'file' => 'views.module',
  );
  return $items;
}

This will embed the view into the hook_menu() instance.

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.