I recently discovered an issue where instead of being replaced by the node's title, Pathauto would simply output the string '[title-raw]'. After some extensive debugging, I found that it was because the $type variable sent to hook_token_values was being changed from 'node' to an array of irrelevant information before node_token_values was called. Now, this is also do to the fact that I altered the module_invoke and module_invoke_all functions to pass arguments by reference as described here. Arguments passed by reference is needed by other modules so I could not change it back, so I further debugged to see what function was altering $type. I found it to be the function content_token_values. So, I ended up changing:

      $type = content_types($node->type); //  <-------------------------------------------
      $node->build_mode = 'token';
      $node->content = array();
      content_view($node);
      // The formatted values will only be known after the content has been rendered.
      drupal_render($node->content);
      content_alter($node);

      $field_types = _content_field_types();
      foreach ($type['fields'] as $field) { //  <-------------------------------------------

to simply:

      $types = content_types($node->type); //  <-------------------------------------------
      $node->build_mode = 'token';
      $node->content = array();
      content_view($node);
      // The formatted values will only be known after the content has been rendered.
      drupal_render($node->content);
      content_alter($node);

      $field_types = _content_field_types();
      foreach ($types['fields'] as $field) { //  <-------------------------------------------

This preserved $type to be used by other modules.

I understand that this is a bit convoluted because I pretty much created the problem by forcing variables to passed by reference in the invoke functions, but I find it necessary bring this up somewhere.

CommentFileSizeAuthor
#1 986612-cck-token-type-parameter.patch1.21 KBDave Reid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Needs review
FileSize
1.21 KB

Indeed, this is always a best practice to make sure we're not overwriting parameter variables.

yched’s picture

Status: Needs review » Fixed

Committed to both 2.x and 3.x branches. Thanks !

Status: Fixed » Closed (fixed)

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