Handle tokens correctly when more than one module defines a given token

rfay - September 24, 2009 - 20:31
Project:Token
Version:6.x-1.12
Component:Code
Category:bug report
Priority:normal
Assigned:rfay
Status:needs review
Description

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')

#1

rfay - September 25, 2009 - 15:56
Assigned to:Anonymous» 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.

#2

rfay - September 26, 2009 - 20:56
Status:active» needs review

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.

AttachmentSize
token_module_array_resolution_587148_01.patch 856 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.