I've created a Domain Tokens module that presents some useful tokens for your domains.

Right now it uses a Pathauto function to make domain tokens path safe, but maybe there shouldn't such a dependency?

agentrickard: I don't know if you want to add this little helper to the main module, or if I should get a CVS account and create a new project for it.

Comments

agentrickard’s picture

Status: Needs review » Needs work

I would remove the Pathauto dependency. Can you post as a normal patch to domain.module?

blackdog’s picture

Status: Needs work » Needs review
StatusFileSize
new1.83 KB

Allright, here's a patch for domain.module. I've created a small cleaning function, but perhaps someone can take a look to see that it's doing it's job properly.

agentrickard’s picture

You should not use the cleanstring on the sitename, just use check_plain().

You might also create a token for the source domain.

blackdog’s picture

StatusFileSize
new2.92 KB

Added tokens for the default domain.

There are two tokens for sitename, one (the raw value) just uses check_plain, the other uses cleanstring.
I created this to be able to use the sitename in file paths, hence the cleanstring.

agentrickard’s picture

Ah, then lets call domain_cleanstring() something like domain_url_encode().

blackdog’s picture

StatusFileSize
new2.92 KB

Done.

jacerider’s picture

Exactly what I needed. Thanks! (And works great -- no issues thus far)

blackdog’s picture

Would be nice to get this is. We're using this right now on a soon-to-go-live project.

@JaceRider - is this working for you? Please set this issue as RTBC if so.

agentrickard’s picture

StatusFileSize
new3.03 KB

Attached is an updated patch against HEAD. I changed the token names, so that they all begin with domain- for better grouping.

I still don't quite see the use-case for this feature. How is this useful in a pathauto situation?

It also needs tokens for Domain Source and other node-specific token values, doesn't it?

blackdog’s picture

We don't use it with Pathauto, but for creating file paths with for example file and image field, so we can separate uploads between domains. I'm sure there are other tokens that can be useful too, but these seem like a good start.

agentrickard’s picture

Version: 6.x-2.0-rc5 » 6.x-2.0-rc6

And that is done through a custom module or a contrib that I can test againat?

I can see the use-case for file folders -- this actually came up today at DrupalCON DC.

blackdog’s picture

Both File and Image field has token support so you can just grab those and give it a try.

skizzo’s picture

would this implement the functionality described
in http://drupal.org/node/198131 ?

agentrickard’s picture

skizzo -- Not quite the same.

The tokens approach is a good solution for the current inability to swap files directories per domain, which is complicated by the nature of the {files} storage table in Drupal core.

agentrickard’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new1.4 KB

Tested and committed to HEAD.

@blackdog -- This is an awesome feature!

I did, btw, test Domain Source (see attached), but it does not work since the $node->domain_source element may not be set when uploading files to a new node. So I have scrapped it.

For the majority of user-cases, this patch should be perfect.

Thanks again!

nonsie’s picture

Tested as well - seems good to me.

blackdog’s picture

Thanks agentrickard!
And thanks for doing this even on DC/DC, hope you're having a good time!

agentrickard’s picture

It actually gave me an excuse to go hide in a quiet room for 90 minutes :-)

jdlind38’s picture

Will this feature be in the next release?

agentrickard’s picture

Yes. It is already in HEAD.

mitchell’s picture

Issue tags: +clean path

I found this issue when looking for other situations where modules need clean paths. After talking to greggles, the way to accomplish this is in this pathauto issue: #212208: allow other modules to affect strings (to help with custom accent/string replacement) and a new Clean Path module.

Here's a link to other issues with the clean path tag.

agentrickard’s picture

@mitchell

That issue seems to be entirely unrelated, unless you are going to use the new pathauto hook to rewrite URL path per-domain, which will not be supported by DA core.

mitchell’s picture

@agentrickard: I'm not really sure how the Clean Path API could be used with DA because of its specific needs. I imagine the module would work similarly to Token, so in whatever sense you would need paths generated from "unclean" strings, this future module would be able to help.

dave reid’s picture

Version: 6.x-2.0-rc6 » 6.x-2.x-dev
Status: Patch (to be ported) » Needs review
StatusFileSize
new3.58 KB
new6.63 KB

Some follow-up patches for both 6.x-2.x and HEAD/7.x-3.x:

1. In D6's hook_token_list() you need to check if ($type == 'global' || $type == 'all') when listing your tokens otherwise they get listed even we only want to show non-global node-related tokens. To see this have the latest pathauto and token installed and go to the Pathauto patterns page.
2. Moved D7 token implementations to domain.tokens.inc.
3. Reworked the D7 tokens to provide a base 'domain' token type, a 'current-domain' global token type, and a 'default-domain' global token type. This way, we can properly chain stuff like [node:source-domain:url]. A couple before/afters:
Before: [domain:domain-id], After: [current-domain:id]
Before: [domain:domain-default-id], After: [default-domain:id]

Also, I would *highly* recommend *not* altering your tokens aside from sanitation. The stuff with domain_url_encode() just screams out at me, but I haven't touched it here.

dave reid’s picture

StatusFileSize
new6.6 KB

copy/paste errors with the D7 patch

dave reid’s picture

Issue tags: +token

Adding tag

agentrickard’s picture

The domain_url_encode() bit was put in by the OP as a way to strip out non-Alphanumeric characters. I suppose it's not necessary in most cases because PathAuto will do that for us. I am hesitant to remove that from x.2 versions, though, as people may be using it.

dave reid’s picture

If people want pathauto-style tokens for use with uploads they should be using http://drupal.org/project/filefield_paths which cleans its tokens using pathauto if available.

dave reid’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
StatusFileSize
new6.6 KB

Fixed error with 'Current domain' name being used on [default-domain:?] tokens.

agentrickard’s picture

Committed to HEAD.

I am reluctant to commit this to 6.x.2 and 7.x.2 because doing so may break expected functionality.

Keeping as 'needs' review for those two branches.

dave reid’s picture

I've just committed a change to Pathauto to display global tokens in the Patterns page, so users will still see domain tokens with the D6 patch. The D7 patch should also be applied to 7.x-2.x because you shouldn't straight port tokens from D6 to D7 since the API changed. Providing a re-usable domain token type, and then current-domain and default-domain is recommended. Everyone is going to have to change all their tokens in when migrating to D7 anyway, so let's just have them do the right thing rather than having to make them change again when they update to Domain 7.x-3.x.

Side note that I'm working on providing a token upgrade API in token.module that modules can use and/or provide their own token upgrades for other modules to use.

dave reid’s picture

I've also filed #945122: Re-use the token tree UI and fix token integration in FileField Paths to have them re-use the provided token tree UI that's available in token.module rather than re-coding their own token display that does things wrong.

agentrickard’s picture

Committed to 6.x

agentrickard’s picture

Status: Needs review » Fixed

Committed to 7.x.2.

Status: Fixed » Closed (fixed)
Issue tags: -token, -clean path

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