Hi,

I have created a view that adds additional tabs (using Page Settings - Menu) to a specific nodetype. The tab or view is to show the outstanding tasks that have been associated to the node.

I would like to be able to show the number of Tasks outstanding when viewing the node. eg. The tabs would look like:

VIEW TASK(2)

when there are 2 tasks outstanding, or if there were 5 tasks outstanding it would look like

VIEW TASK(5)

Is this possible with the standard views? if its not, is it possible using some CSS or PHP code somewhere?

thanks for the help.!

Comments

merlinofchaos’s picture

Status: Active » Fixed

This is not possible with standard Views.

It *might* and I stress *might* be possible to do this utilizing hook_menu_alter() (and your module weight must be higher than that of Views, which is 10) and changing the title of the menu item to go to a callback function. You could then run the view to get the number to display.

Please note that doing this could add a significant performance burden to your site.

ozecho’s picture

thanks for the quick response... I appreciate it!

ozecho’s picture

In case anyone else wants to do this in the future... here is the few lines of code I created to have my task count in the tab heading:

function task_menu_alter(&$items) {
   $items['node/%views_arg/task']['title callback'] = "task_node_title"; 
}

function task_node_title() {
  $count = db_result(db_query("select count(*) from {content_type_task} where field_task_status_value < 10 and field_task_node_nid = %d",arg(1))); 
  return "Tasks (".$count.")";
}

Thanks Merlin for the tip on the module weight... I set my module "Task" to a module weight of 11 (had to edit the "system" table through the database) and it all worked great!

Thanks again...

Status: Fixed » Closed (fixed)

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

reinis.berzins’s picture

Status: Closed (fixed) » Needs review

Thanks! This custom module code works! However it breaks cron, login, save node, flush cache and all other operations (except browsing from page to page) on my website. In the log I find the following error:
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

And it still continues breaking cron, login etc. after I deleted the function TAB_COUNTER_title_callback() or even replaced with a static title: $items['node/%views_arg/questions']['title'] = 'Questions';

I tried to restrict this custom module to work on certain paths only like node/%, but with IF statements in the code it stops working at all:

function TAB_COUNTER_menu_alter(&$items) {
   if (arg(0) == 'node' && is_numeric(arg(1))) {            <-- IF statement turns the whole code non-working.
	$items['node/%views_arg/questions']['title callback'] = 'TAB_COUNTER_title_callback';
   }
}
function TAB_COUNTER_title_callback() {
  $count = db_result(db_query("SELECT COUNT(nid) FROM {node_comments} WHERE nid = %d", arg(1)));
  return 'Questions ('.$count.')';
}

Does anybody have any idea how to make this custom module lighter for the website or restrict to work on certain paths only?

dawehner’s picture

Status: Needs review » Fixed

   if (arg(0) == 'node' && is_numeric(arg(1))) {            <-- IF statement turns the whole code non-working.

You have to know that hook_menu_alter is not executed on every page but only on clearing the cache which can happen anytime.
You simply do not need this if, you alter the menu definition, that's it.

reinis.berzins’s picture

Thanks, dereine, for clarification! But still this code (even without IF()) breaks cron, flush cache and save (in any submission forms) actions. In fact, after I refresh the resulting white screen, I see that all these actions have actually been completed "successfully". Besides the white screen I also get the same error in the log:
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
I also tried increasing memory_limit in php.ini and and disabling other modules that might consume memory, but every time I discover that only this simple custom module code produces the error.

dawehner’s picture

What is your current code you use?

reinis.berzins’s picture

I created a custom module tab_counter.module, and everything this file contains is:

function TAB_COUNTER_menu_alter(&$items) {
    $items['node/%views_arg/questions']['title callback'] = 'TAB_COUNTER_title_callback';
   }
}
function TAB_COUNTER_title_callback() {
  $count = db_result(db_query("SELECT COUNT(nid) FROM {node_comments} WHERE nid = %d", arg(1)));
  return 'Questions ('.$count.')';
}

But the same error happens even if the tab_counter.module contains only:

function TAB_COUNTER_menu_alter(&$items) {
    $items['node/%views_arg/questions']['title'] = 'Questions';
   }
dawehner’s picture

So are you sure this path is correct? "node/%views_arg/questions"

reinis.berzins’s picture

Yes, I'm 100% sure, because by using this custom module - on every Node page (e.g. node/1318) I get the existing Views Menu Tab "Questions" successfully renamed to e.g. "Questions (10)", and as I click on the "Questions (10)" Menu Tab I get directed to the right page (e.g. node/1318/questions).

But as I said it breaks cron, login, logout, save, etc. turning into a white screen.

reinis.berzins’s picture

Thank you, dereine, anyway!

I found a totally different solution http://drupal.org/node/802012 with function phptemplate_preprocess() which didn't crash login, logout, save and cron operations on my website.

Status: Fixed » Closed (fixed)

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