API that allows to have different build modes or page callbacks for node/%/[something], depending on node type or other criteria.

It can be seen as an alternative to panels/ctools page variants.

Usage:
(this is going to be moved to a documentation page or README.txt some day)

<?php
/**
 * Implements hook_nodeaspect()
 * Shortcut for hook_menu(), and for view mode registration
 */
function bw_groups_nodeaspect($api) {

  // Register a nodeaspect path node/%node/forum
  $api->page('forum');
  // Register a nodeaspect path node/%node/wiki
  $api->page('wiki');
  // Register a nodeaspect path node/%node/wiki/view
  $api->page('wiki/view');
  // Register a nodeaspect path node/%node/wiki/edit
  $api->page('wiki/edit');
  // Register a nodeaspect path node/%node/members
  $api->page('members');

  // Register view modes
  $api->viewMode('group_forum', 'Group discussions');
  $api->viewMode('group_wiki', 'Group wiki');
  $api->viewMode('group_wikiedit', 'Group wiki edit');
  $api->viewMode('group_members', 'Group members');
}


/**
 * Implements hook_nodeaspect_page()
 *
 * This is called during menu_get_item().
 */
function bw_groups_nodeaspect_page($node, $suffix, $api) {

  // This stuff is specifically for node type "group".
  if ($node->type === 'group') {
    $u = $GLOBALS['user'];
    $is_member = og_is_member($node->nid);

    $skip = FALSE;
    switch ($suffix) {

      case '':
        $api->title($node->title);
        $api->viewMode('full');
        break;

      case 'view':
        // That's the "default local task".
        $api->tab(t('Overview'), -4);
        break;

      case 'forum':
        $api->tab(t('Discussions'), -3);
        $api->viewMode('group_forum');
        $api->pageTitle(t('Dedicated forum for @group_name', array('@group_name' => $node->title)));
        break;

      case 'wiki':
        $api->tab(t('Wiki'), -2);
        $api->viewMode('group_wiki');
        break;

      case 'wiki/view':
        $api->tab(t('View'), -0);
        $api->viewMode('group_wikiedit');
        break;

      case 'wiki/edit':
        $api->tab(t('Edit'), 1);
        $api->viewMode('group_wikiedit');
        break;

      case 'members':
        $api->tab(t('Members'), -1);
        $api->viewMode('group_members');
        break;
    }
  }
}
?>

Project Information

Downloads