If you view a node using a view_mode_page menu_get_object() will return NULL.
This can cause issues integrating with other modules, and also means the correct node-type-CONTENT-TYPE-CLASS isn't added to the body tag.

Comments

leon.nk created an issue. See original summary.

leon kessler’s picture

My quick fix is to not use view_mode_page, and instead add the pages yourself using a hook_menu_alter().

E.g.

/**
 * Implements hook_menu_alter().
 */
function my_module_menu_alter(&$items) {
  if (isset($items['node/%node'])) {
    $items['node/%node/new-page'] = $node['node/%node'];
    $items['node/%node/new-page']['title'] = t('New Page');
    $items['node/%node/new-page']['type'] = MENU_CALLBACK;
  }
}

I believe the %node auto-load argument is what achieves the router object being available.

I haven't had enough time to dig around with the code in this module, but I'd imagine it would be possible to fix this (as it also uses hook_menu_alter()).

Note that the above code will add your page to all content types.

leon kessler’s picture

Status: Active » Fixed

Ah the answer was right there!

To ensure menu_get_object() can load the node, set the URL Pattern for your view mode page to use the %node argument.
E.g.
node/%node/new-page

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.