Currently, if more than one module defines a token with a given name, the token value becomes an array, because array_merge_recursive is used to build the result array. This completely confuses all the user modules, making the token useless.

I propose:
1. Documentation on how to declare tokens. Do they have to namespace their tokens?
2. Choosing the first token of the array and providing it in this case. Perhaps module weights could be used in the battle then, but at least there would be a way to resolve this.

Right now, the only resolution is to patch one of the modules to namespace the token. I just had to do this in #587140: Token name collision with activity module (token: 'operation')

Comments

rfay’s picture

Assigned: Unassigned » rfay

Per conversation on IRC with @greggles:

I'll try to create a patch which:

1. Chooses the last token value (highest-weighted module's version) instead of returning the array.
2. Emits an error message to watchdog (perhaps to DSM)?

The error message to watchdog will need to be throttled somehow or it will fill the log.

rfay’s picture

Status: Active » Needs review
StatusFileSize
new856 bytes

The attached patch does as described in #1.

I'm certainly open to a simpler approach, but didn't find one. I am convinced that token_get_values() is the correct place to be doing this checking. A more extensive change to the actual processing of tokens would be another way to deal with this problem.

I chose not to emit a drupal_set_message() as it is enormously intrusive and punishes the integrator or user for something they may not be able to fix.

rfay’s picture

Assigned: rfay » Unassigned
dave reid’s picture

Version: 6.x-1.12 » 6.x-1.x-dev
Assigned: Unassigned » dave reid
StatusFileSize
new2.04 KB

Here's a modified version that extracts this logic into its own function. We need this is now that we're adding more tokens like node-url and node-path.

dave reid’s picture

StatusFileSize
new2.04 KB

Re-uploading for the bot to test.

dave reid’s picture

Status: Needs review » Fixed
rfay’s picture

Wow, I never thought that would see the light of day :-)

dave reid’s picture

Yeah sorry it took so long. This got bumped in priority once we added the [node-url] tokens which seem to be defined in lots of other modules.

Status: Fixed » Closed (fixed)

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

mariagwyn’s picture

Status: Closed (fixed) » Active

On what version is this fixed? And what does the "fix" look like? I use notifications, still get the error message in the log, though functionality does not seem to be impaired. I also commented on the notifications issue hoping to get it addressed.

dave reid’s picture

Status: Active » Fixed

All versions it was fixed. Instead of blowing up and completely breaking your site, token.module now alterts you when more than one module defines a token. Most times it will have to be fixed in the offending module since no other module should define the same tokens as token.module. So, in this case this needs to be fixed in the notification module.

Status: Fixed » Closed (fixed)

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

allan1015’s picture

If this is the wrong place to post this please let me know
I understand these issues may be from other modules, but I read somewhere in Toekn issues that you all were attempting some general fix and someone said to let you know of any Duplicate Token issues

Using Token 6.x-1.x-dev (2010-Dec-14)

The Notification Module, 6.4-beta7 still has this issue - a patch seems to not be fully applied
http://drupal.org/node/845250

The CCK Signup Notifications (enabled in Notifications part fo Modules but I think its CCk Signups issue)
http://drupal.org/node/1002784