Hi,
a typical thing I do with Display Suite is to make a node sub-page (tab / local task next to view, edit etc) via hook_menu(), and let it render the node in a custom build mode.
This can be creatively combined with custom fields and views_attach.module.

I wonder if we could simplify this process, so the admin / developer would have to do only one thing, to create the build mode and the router item at once.

I am undecided if this "one thing" should be to implement a hook (= code), or to click around in the admin backend. Maybe we can provide both.

I might help out with a patch, or even make a separate module for this, but would like to see some opinion first, and maybe some useful hints.
Thanks!

Comments

swentel’s picture

Starting with a hook sounds good enough for me. ND can implement hook_menu() and call a hook which pass in information. I guess that hook should only pass a title for the tab, and the build mode so we we can pass this on as a page argument. We'll probably have to use our own page callback, which will basically become a copy of node_page_view (say nd_page_view), with an extra param which will be the $build_mode.

I personally never had the need for such functionality, so not sure if we need to make this available already in the admin too. Depends how much you want to write I guess :)

donquixote’s picture

For my taste, a hook is fine.
(and easier to deploy anyways)

Ok, I am sure I can figure out most of this myself.
The one thing I would ask you (so I don't have to investigate myself):
I want to automatically create a build mode for every page aspect.
The build mode name and machine name can by default be identical with the path suffix and the tab title, but I want the possibility to override this (so changing the path does not require changing the build mode name).

The question:
What is the best way to declare build modes programmatically, and not get in conflict with the user-created build modes?

donquixote’s picture

Quick update,
I have something working on my local test site, a module "nodeaspect" with a hook_nodeaspect() to define your own build modes and aspect pages.

It does create router items, permissions and build modes.

This is how your example module implementation would look like:

<?php
/**
 * Implements hook_nodeaspect()
 *
 * @param $rha :nodeaspect_RHA
 *   Receptive hook argument.
 */
function mymodule_nodeaspect($rha) {

  // Create a buildmode with machine name 'about' and title 'About'.
  // This will also create a permission "nodeaspect view about"
  $rha->buildmode('about', 'About');

  // Define a node sub-page (local task) 'node/%node/about' with title 'About',
  // buildmode 'about' and access callback 'mymodule_about_access'.
  $rha->page('about', 'About', 'about')->accessCallback('mymodule_about_access');
}

/**
 * Access callback for node/%node/about
 */
function mymodule_about_access($node, $buildmode, $subpath) {
  return
    // We only want this to show up on node type 'project'.
    $node->type == 'project' &&
    // Perform the default access checks,
    // that is node_access('view', $node) and user_access("nodeaspect view $about")
    nodeaspect_page_access($node, $buildmode, $subpath)
  ;
}
?>

Please note that most of this is comments.

I wonder if we should aim to add this to any existing project (nd, nd_contrib) or make it a new project.

donquixote’s picture

Also, I wonder if I can somehow manipulate the "exclude matrix" programmatically, if a build mode applies to only some node types.

swentel’s picture

The exlude matrix is a bunch of variables - not the nicest way to store those settings, but it works in the 6 branch, see ds_build_modes_matrix_submit()

xtfer’s picture

Status: Active » Closed (won't fix)

Unless anyone is planning on updating this thread with more information about nodeaspect or a similar implementation, this is now closed. :)

donquixote’s picture