I wanted to use the token provided by this module to feed the short URL element of the metatag module and generate the short URLs automatically and I noticed there is only a token for node's URLs.

I improved this by providing an URL wide token for every URL token defined, and because unaliased URLs are also URL-type, you get those too.

Now you can do:

[node:url:shorten], [node:url:unaliased:shorten], [current-page:url:shorten] and [current-page:url:unaliased:shorten] and any other URL token defined by the token module or any other module for that matter.

I also removed the shorten_generate_token variable. For me it really makes no sense to have it. Yes, it can have a performance impact, but the token is only generated if it's used, so you should be aware of what you are doing anyway, it's not that it will create the token URL for every single page unless you specifically instruct to do so (like I am doing with metatag module).

Then also modified the install file to clear this variable from the db, and I noticed an update from 6.x was left there, so I went ahead and removed it altogether so a slightly cleanup on the install file.

I did left the short-url there for backward compatibility so not to break anyone using it.

Comments

hanoii’s picture

Status: Active » Needs review
StatusFileSize
new4.27 KB
hanoii’s picture

Assigned: hanoii » Unassigned
icecreamyou’s picture

I also removed the shorten_generate_token variable. For me it really makes no sense to have it. Yes, it can have a performance impact, but the token is only generated if it's used, so you should be aware of what you are doing anyway, it's not that it will create the token URL for every single page unless you specifically instruct to do so (like I am doing with metatag module).

I believe that sometimes all tokens of a given type (e.g. "node") are generated regardless of which ones are used, but it's been so long since I've looked at this that I don't remember why I think that.

Generally I'm in favor of the new tokens, but I'd really like to make sure they don't produce unexpected/unnecessary overhead before committing.

(Also, you left two stray dpm()s in the patch.)

hanoii’s picture

StatusFileSize
new4.22 KB

Oops, attached w/o the dpm()s.

As far as the tokens being generated, well, I am certainly not a tokens expert, however, by following the code it seems that a token is only generated when the token is actually found, so I don't think how or when the generation can be triggered on its own.

  • IceCreamYou committed 4a5af1a on 7.x-1.x
    Issue #2317241 by hanoii: Added Better token support.
    
icecreamyou’s picture

Status: Needs review » Fixed

Tested to confirm and it looks like you're right. Committed to dev. Thanks for your contribution!

Status: Fixed » Closed (fixed)

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