Currently we're duplicating a lot of functionality with URL related tokens, creating separate tokens for absolute URLs, and the simple URL aliases of the path. I think it would make a lot of sense to make an [url:*] token type that has the following tokens:

[url:absolute] - The result of url() with 'aboslute' => TRUE (e.g. 'http://example.come/en/my-node-1-alias')
[url:relative] - The result of url() with 'absolute' => FALSE (e.g. '/en/my-node-1-alias')
[url:path] - The internal path of the URL (e.g. 'node/1')
[url:alias] - The alias of the URL (e.g. 'my-node-1-alias')

Any chained token should default to using absolute URLs (i.e. [node:url] would be the same as [node:url:absolute]).

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new8.02 KB

Status: Needs review » Needs work

The last submitted patch, 1010822-url-token-type.patch, failed testing.

greggles’s picture

Makes sense to me.

realityloop’s picture

+1 this will be very useful

fago’s picture

Yep, that sounds useful. However, I guess any module making use of that should introduce a dependency on the token module then? As without it the tokens would show up in token info, but not work - right? Or better, just wrap any url tokens in a module_exists('token') check?

dave reid’s picture

Actually it works pretty well. If you define a token with an undefined type, it just won't be expanded further in the token tree listings and won't work. So any module can do:

$info['tokens']['mytype']['url'] = array(
  'name' => t('URL'),
  'description' => t('The URL of my type item.'),
  'type' => 'url',
);

And without token module installed, using [mytype:url] works just fine (since the providing module is responsible for that), but if Token module is installed, and the module also does the following in its hook_tokens() then the url type chained tokens (e.g. [mytype:url:alias] work automatically.

    // Chained token relationships.
    if (($url_tokens = token_find_with_prefix($tokens, 'url'))) {
      $replacements += token_generate('url', $url_tokens, array('path' => 'mytype/1'), $options);
    }
dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new19.31 KB

Status: Needs review » Needs work

The last submitted patch, 1010822-url-token-type.patch, failed testing.

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new20.81 KB
fago’s picture

oh, I see. That's indeed neat.

dave reid’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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