I have installed token 5.x-1.10, pathauto 5.x-2.1, taxonomy_menu 5.x-1.03 with this patch and page_title 5.x-2.x-dev (or 5.x-2.0-alpha5) and have some problems.
Very often I got a message "Access denied" when browsing admin pages. When I turn off page_title module, all goes to work good, but with enabled page_title I got this error again.

And I found regularity with it: when I opening page like admin/build/menu every first loads gots the "Access denied" error, but when I refresh page - all show good without errors. And this repeats every 2 times.

I found that the error is shows only where Drupal loads menu from cache, if I disable menu caching - all works good.

And I found a function, that leads to this problems - calling function token_get_list('taxonomy',$term) in hook_menu() function. When I comments this function, all works good.

Does anybody have problems like this or ideas how to solve this problems?

Comments

murz’s picture

Title: Got "Access denied" when calling token_get_values('taxonomy',$term) » Got "Access denied" when calling page_title_get_title() in hook_menu functions

I have found a problematic function:

 function page_title_get_title() {
...
    return strip_tags(drupal_get_title());
...
}

If I replacing drupal_get_title() to something like 'Test page title' in this string, all works good but [page-title] token value sets to 'Test page title'.

nicholasthompson’s picture

This is VERY odd!

I'll have to investigate this. I cant even begin to think why this would happen!

murz’s picture

I try a fresh install of Drupal 5.7 and detect this bug on it too.
You can see this bug when install to a fresh Drupal modules page_title and token.
And wrote a hook_menu function in some module with calling token_get_list() in it.
After that try to refresh in browser, for example, 'admin/build/menu' page many times. Each second time I see an 'access denied' error :(

murz’s picture

Status: Postponed (maintainer needs more info) » Active

I try to add a counter in function page_title_get_title() that counts the number of function launches in one page load.
And when I skip calling drupal_get_title() on first function start when it calls more than 1 times, all works good.
My modifications for this:

function page_title_get_title() { 
  $display_options = variable_get('page_title_display', array());
  $node = page_title_set_node();
  
  if ($display_options[$node->type] && !empty($node->page_title)) {
    return check_plain(strip_tags($node->page_title));
  }
  else {
     static $pagetitle_count;
     $pagetitle_count++;
     echo " starts count: $pagetitle_count ";
     $drupal_get_title=$pagetitle_count<2?'early-for-gettitle':drupal_get_title();
     return strip_tags($drupal_get_title);
  }
}

But I can't found a method to detect times where I mustn't call drupal_get_title() function. Because when I see first run, I don't know how many times this function must run after that.
I think, we needs to look on something like drupal bootstrap phase or menu generation state.
I try to compare global $_menu in each run, but it is same every call :(

nicholasthompson’s picture

Status: Active » Postponed (maintainer needs more info)

can you show me you code in template.php for the _phptemplate_variables function please?

murz’s picture

Status: Active » Postponed (maintainer needs more info)

I try it in fresh Drupal install with standart 'garland' template, _phptemplate_variables function is:

function _phptemplate_variables($hook, $vars) {
  if ($hook == 'page') {

    if ($secondary = menu_secondary_local_tasks()) {
      $output = '<span class="clear"></span>';
      $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
      $vars['tabs2'] = $output;
    }

    // Hook into color.module
    if (module_exists('color')) {
      _color_page_alter($vars);
    }
    return $vars;
  }
  return array();
}
murz’s picture

I found where executes first page_title_get_title(), thats leads to the error - in includes/menu.inc function imenu_execute_active_handler():

function menu_execute_active_handler() {
  if (_menu_site_is_offline()) {
    return MENU_SITE_OFFLINE;
  }
echo "call menu_get_menu start"; // added by Murz
  $menu = menu_get_menu();
echo "call menu_get_menu end"; // added by Murz

First call executes in this place and other, that executes without errors, calls in later code. I trying to search a method for distinguish this and another calls in function page_title_get_title().

nicholasthompson’s picture

I assume you've read the readme.txt which tells you to add some code to template.php (hence me asking to see it)?

You shouldn't need to worry about the menu callbacks at all.

Are you using Page Title 2 DEV or Alpha5? DEV is not the same as Alpha5... Dev has test code in it for integration with Views.

murz’s picture

I try both (Page Title 2 DEV and Alpha5). The code of function page_title_get_title() is same on all versions.
Modifications in template.php influence only on showing titles and don't influence the problem function page_title_get_title().
And I try with template.php modifications and without it.

The problem is that drupal can't get current title with function drupal_get_title() in states when menu isn't already been builded. But page_title module use 'global' token hook that calls in all states. And when it calls before first call of menu_get_menu(), it breaks the correct menu building system.

I think you need to find another method to get drupal page title or check the state of menu before calling drupal_get_title().

nicholasthompson’s picture

Priority: Normal » Critical
Status: Postponed (maintainer needs more info) » Active

I'll investigate this.... Thanks.

nicholasthompson’s picture

Status: Active » Postponed (maintainer needs more info)

Murz - is this still happening?

murz’s picture

Yes, I can't find a normal method to solve this issue.
But I have found an exit on my site - I have do a quick hack for token and pathauto modules on my site for disabling calling page_title_get_title() in states when menu isn't already builded.
But any other modules, as I think, can call drupal_get_title() in boot state and will see problems like in my issue. In my site this modules was combination of token and pathauto. Other sites may have another problematic module combination.
Maybe better is to ignore this issue at now time (for release a stable or beta version of this module) and add in INSTALL.txt or README.txt information about this issue for easier searching bug source for other developers?

If I have found or get some ideas about this issue, I put they here, but at now I have no time to search a fix and use hacked modules on my site.

nicholasthompson’s picture

Status: Postponed (maintainer needs more info) » Postponed

I really cant understand why this error happens... It appears that its only you that is having the problem. I'm running this module on dozens of sites with many combinations of modules and versions of modules and I have never had this. Nobody else has reported it - it appears to be very specific to you. Maybe you have a bad module or a funky server config?! I honestly dont know!

Postponing for now unless anyone else can help out or reproduce.

murz’s picture

You and other on any server and any Drupal 5.x can reproduce this bug when it try to call page_title_get_title() in hook_menu() function.
For example, in my situation, I have taxonomy_menu module, that must rebuild menu items every time on menu rebuild. And it do this with this steps.

  1. Calling taxonomy_menu_menu(), that gets terms that must be builded
  2. Getting the aliases for taxonomy tems. In this state it calls function pathauto_get_placeholders(), that calls function token_get_values() with $type='taxonomy' and getting token values for building path.
  3. Function token_get_values() builds for default not only taxonomy tokens, but all global tokens! But global tokens have $tokens['global']['page-title']; token from page_title_token_list() function that calls function page_title_token_values().
  4. Function page_title_token_values() calls function page_title_get_title() that use function drupal_get_title().
  5. Function drupal_get_title() calls function menu_get_active_title() that try to get menu item and build the menu. But menu is empty because hook_menu() process doesn't finished already! And function menu_get_active_title() calls function menu_get_menu() that write to cache (to global $_menu variable and cache) empty menu list and return empty active menu item.
  6. After that hook_menu() process ends and all other calls to get menu items return empty results! For this reason, we see the problems with empty pages and "Access denied" errors.

We can easy solve this issue if we move page_title token hook from 'global' to another place, for example - to node. Because in 'global' place we must not calling functions that works with menu items such as drupal_get_title() function.

Or another variant is to add for function token_get_values() new option to ignore global calls from page_title_get_title() function.

At now you can write in readme.txt that developers must not use token module in hook_menu() functions with page_title module.

murz’s picture

I have create a feature request for token module: http://drupal.org/node/263110
When it have been implemented, we can modify token_get_values() calls and solve this issue.

nicholasthompson’s picture

Ohhh Thanks for the explanation - I see the problem now!

I wonder if there is anything in $_POST we can look at to see if the menu is being rebuilt?!

We cant move the page title to node because page title's apply 'globally' throughout the site, not just to nodes.

greggles’s picture

Project: Page Title » Token
Version: 5.x-2.x-dev » 6.x-1.x-dev
Status: Postponed » Active

I'm moving this to token so that we can keep the history and get nicholasThompson's ideas on the patch you provided there.

@nicholasThompson - the solution that Murz has provided would excluded global tokens from use by Page Title. Does that seem reasonable to you? My feeling is that if we exclude global tokens then people would be disappointed that some of the most important tokens are gone, right?

greggles’s picture

@nicholasThompson...ping - the proposed patch is http://drupal.org/files/issues/token_add_ignore_global_0.patch

murz’s picture

Status: Active » Closed (fixed)

Seems that this bug is fixed, closing.