Could you add token support to the premium messages? I would like to add a link to the login page (/user/login) from my messages with the ?destination=node/123 appended to the link.

At present I'm using the following theme override to achieve this but it would be much easier with tokens

function mytheme_nopremium_message($node) {
  $message = t(nopremium_get_message($node->type));
  $message = preg_replace('/href="\/user\/login"/i', 'href="/user/login?'.drupal_get_destination().'"', $message);
  return check_markup($message);
}

Comments

roball’s picture

Thanks for this useful code, SkidNCrashwell. I needed the same, having

<a href="/user/login?destination=node"><strong>Log in</strong></a> to read the full content of this article (Members only).

set as the Default message at admin/settings/nopremium. I am using

function THEMENAME_nopremium_message($node) {
  $message = t(nopremium_get_message($node->type));
  $message = preg_replace('/("\/user\/login\?destination=node)"/', '$1%2F' . $node->nid . '"', $message, 1);
  return check_markup($message);
}

in template.php residing in the THEMENAME directory of the used theme. This solution is a little bit smarter I think.

anrikun’s picture

@SkidNCrashwell, @roball:
You don't need preg_replace here. A right way to achieve this is:

Having as message:
<a href="/user/login?destination=node/!nid"><strong>Log in</strong></a> to read the full content of this article (Members only).

Use:

<?php
function THEMENAME_nopremium_message($node) {
  $message = t(nopremium_get_message($node->type), array('!nid' => $node->nid));
  return check_markup($message);
}
?>
roball’s picture

Title: Request for tokens to be available in messages » Allow !nid token in messages

Excellent, anrikun, the code gets smarter and smarter. How about integrating the !nid token into your module, so there is no more need to touch template.php at all, as originally suggested in this issue?

anrikun’s picture

Title: Allow !nid token in messages » Allow tokens in messages
Version: 6.x-1.2 » 7.x-1.x-dev

!nid token is not enough. I think we should add global and node tokens :-) User tokens too if possible.
Let's do it in 7.x first.

roball’s picture

Sounds like a plan :-) BTW, thank you for this very useful module - it is far better than the original one and the second fork. Just does what it advertises, nothing more, nothing less, and that's exactly how software should work.

varsityblue50’s picture

Issue summary: View changes

Hello there, were the tokens and full HTML issues resolved in the 7.x dev release?

devkinetic’s picture

I just looked at this and this sounds dead simple. Adding token_replace() to the theme function should be all that is needed as token is built into the D7 API. Looks like the token module is still needed for "... a token UI browser, and token support for core module like Fields and Profile." so what this topic should be about is if we want to extend token support beyond D7 core, and allow for those extra features.

elstudio’s picture

I've uploaded a patch that allows standard token replacement in the premium messages.

It's set to work with the html-enabled messages from #1149302.