General token parser (API), does it exist?
Hi, new-user-emails, welcome-mails, pathauto, newsletters, themes, auto_nodetitles and so on. Just a few random examples of token-replacement. Drupal has nothing in this regards, every module on its own, resulting in a lot of code-overhead, inconsistency and all the other downsides of not having a central/modular design. Are there any projects on this? Any APIs, libraries, or exsisting modules that do what I need: centralise token replacement? Or even an existing patch or issue that I missed? What need, more specific, is: * Present the user/admin with a list of available tokens (%username, %site etc) in a help message. * Parse these by replacing tokens with the value of a variable. What I don't need, is: * A new templating engine. * complex if-while etc structures. -- Drupal, Ruby on Rails and Joomla! development: webschuur.com | Drupal hosting: sympal.nl
If I understand it correctly, you mean something like this: - The user has a list of possible values, for example: 18 Monday 09 9 September Sep 2006 06 - Then he can construct a date format by dragging the elements in a rectangle/textfield and adding punctuation characters or static text. - A "template" for that text is created, for example "%M %j, %Y" I already had something like this in mind (specifically for pathauto) and volunteer to code the front-end part. Am 06.12.2006 um 12:53 schrieb Bèr Kessels:
Hi,
new-user-emails, welcome-mails, pathauto, newsletters, themes, auto_nodetitles and so on. Just a few random examples of token-replacement. Drupal has nothing in this regards, every module on its own, resulting in a lot of code-overhead, inconsistency and all the other downsides of not having a central/ modular design.
Are there any projects on this? Any APIs, libraries, or exsisting modules that do what I need: centralise token replacement? Or even an existing patch or issue that I missed?
What need, more specific, is: * Present the user/admin with a list of available tokens (% username, %site etc) in a help message. * Parse these by replacing tokens with the value of a variable.
Konstantin Käfer – http://kkaefer.com/
Op woensdag 6 december 2006 13:30, schreef Konstantin Käfer:
If I understand it correctly, you mean something like this:
- The user has a list of possible values, for example:
No, more a general place/code for something like: http://example.com/admin/settings/user Customize the body of the welcome e-mail, which is sent to new members upon registering. Available variables are: %username, %site, %password, %uri, %uri_brief, %mailto, %login_uri, %edit_uri, %login_url. This is now hardcoded into user.module. And there are many more flavors and concepts that do almost the same, and need to hardcode this. Bèr -- Drupal, Ruby on Rails and Joomla! development: webschuur.com | Drupal hosting: sympal.nl
Bèr Kessels wrote:
Hi,
new-user-emails, welcome-mails, pathauto, newsletters, themes, auto_nodetitles and so on. Just a few random examples of token-replacement. Drupal has nothing in this regards, every module on its own, resulting in a lot of code-overhead, inconsistency and all the other downsides of not having a central/modular design.
Are there any projects on this? Any APIs, libraries, or exsisting modules that do what I need: centralise token replacement? Or even an existing patch or issue that I missed?
What need, more specific, is: * Present the user/admin with a list of available tokens (%username, %site etc) in a help message. * Parse these by replacing tokens with the value of a variable.
if you look at those implementations, there are very few lines of code. i'm not even sure it is worth centralizing. strtr() does all the work ... feel free though to organize a working group and write a DEP specifying an API with forward and backward compatibility requirements to be implemented in phases.
Ber, I also had to rewrite this functionality a few weeks ago for the custom_breadcrumb and custom_links modules. I know that pathauto also dedicates a good chunk of code to it. The substitution code itself isn't hard at all -- it's the central registry of tokens that everyone needs to be able to share. The global ones -- the name of the current user, the name of the site, an so on -- are pretty easy. Do you think it woudl be worthwhile to centralize more complex ones, like 'variations on the creation date of the passed-in node,' and 'the uid of the author of the node', etc? These kinds of tokens are very useful for constructing paths, among other things... --Jeff
The global ones -- the name of the current user, the name of the site, an so on -- are pretty easy. Do you think it woudl be worthwhile to centralize more complex ones, like 'variations on the creation date of the passed-in node,' and 'the uid of the author of the node', etc?
I think the idea of global tokens is rather weird. Now, tokens are always local to a single t() call. If tokens are shared between strings, this is only because it is explicitly done by the coder. If we start making some tokens globally available, there is absolutely no argument against adding more arbitrary tokens to this list. It'll explode into a zoo of random variables. I think we perhaps do need to look at a way of using e.g. PHP code in these welcome mail-like strings. That way, you can use arbitrary code to retrieve any value you need. You could even make it backwards compatible: $text = strtr(drupal_eval($text), array('%token' => ...)); if no <?php ?> tags are used, it reverts to simple strtr() replacement. Steven
On Wed, 6 Dec 2006, Steven Wittens wrote:
I think we perhaps do need to look at a way of using e.g. PHP code in these welcome mail-like strings. That way, you can use arbitrary code to retrieve any value you need. You could even make it backwards compatible:
$text = strtr(drupal_eval($text), array('%token' => ...));
if no <?php ?> tags are used, it reverts to simple strtr() replacement.
IMHO it is a very bad idea to expose PHP here (even if it is not required). Gabor
participants (7)
-
Bèr Kessels -
Gabor Hojtsy -
Jeff Eaton -
Konstantin Käfer -
Moshe Weitzman -
Steven Wittens -
Zohar Stolar