Closed (fixed)
Project:
Project
Version:
6.x-1.x-dev
Component:
Projects
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
12 Apr 2009 at 21:03 UTC
Updated:
5 May 2009 at 19:45 UTC
Some paths use node/%node for project nodes (e.g. node/N, node/N/edit, etc).
Other paths use our custom %project_node menu placeholder, so that we only add the tab on project nodes (e.g. node/N/cvs-access, node/%project_node/edit/issues, etc).
So, there's no easy/reliable way to get the project node from the menu context since you basically always have to call menu_get_object() twice, once using 'node' (the default), and once using 'project_node'. This is a problem, for example, for all the project-specific blocks that require a project context.
Therefore, we should just add a helper function for this, something like:
/**
* Get the project node context from the currently active menu, if any.
*
* @return
* A fully loaded project $node object if the currently active menu has a
* project node context, or NULL if the menu isn't pointing to a project.
*/
function project_get_project_from_menu() {
$node = menu_get_object('project_node');
if (empty($node)) {
$node = menu_get_object('node');
}
return (!empty($node) && $node->type == 'project_project') ? $node : NULL;
}
Any objections or thoughts?
Comments
Comment #1
dwwOr, this (suggested by chx) -- I considered cramming everything into 1 line like this at first but wanted to make it a tad more readable. But, I guess this is more clear:
Comment #2
dwwOhh, to clarify, #1 is actually my code. chx proposed this:
But that's wasteful, since menu_get_object('project_node') already tests
$node->typefor us.Comment #3
dwwTested and committed to HEAD, along with patches to change various spots in project and project_issue to use this.
http://drupal.org/cvs?commit=195948
http://drupal.org/cvs?commit=195950
Comment #4
dwwWhen this is deployed, we need to make sure project, project_issue, and cvslog are all updated at the same time, or we'll get undefined function errors.
Comment #6
dwwThis is now live on d.o. Danithica can fix pivots_block.module to take advantage of this...