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.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | 361018-domain-tokens-D7.patch | 6.6 KB | dave reid |
| #25 | 361018-domain-tokens-D7.patch | 6.6 KB | dave reid |
| #24 | 361018-domain-tokens-D7.patch | 6.63 KB | dave reid |
| #24 | 361018-domain-tokens.patch | 3.58 KB | dave reid |
| #15 | domain-source-tokens.txt | 1.4 KB | agentrickard |
Comments
Comment #1
agentrickardI would remove the Pathauto dependency. Can you post as a normal patch to domain.module?
Comment #2
blackdog commentedAllright, 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.
Comment #3
agentrickardYou should not use the cleanstring on the sitename, just use check_plain().
You might also create a token for the source domain.
Comment #4
blackdog commentedAdded 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.
Comment #5
agentrickardAh, then lets call domain_cleanstring() something like domain_url_encode().
Comment #6
blackdog commentedDone.
Comment #7
jacerider commentedExactly what I needed. Thanks! (And works great -- no issues thus far)
Comment #8
blackdog commentedWould 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.
Comment #9
agentrickardAttached 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?
Comment #10
blackdog commentedWe 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.
Comment #11
agentrickardAnd 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.
Comment #12
blackdog commentedBoth File and Image field has token support so you can just grab those and give it a try.
Comment #13
skizzo commentedwould this implement the functionality described
in http://drupal.org/node/198131 ?
Comment #14
agentrickardskizzo -- 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.
Comment #15
agentrickardTested 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!
Comment #16
nonsieTested as well - seems good to me.
Comment #17
blackdog commentedThanks agentrickard!
And thanks for doing this even on DC/DC, hope you're having a good time!
Comment #18
agentrickardIt actually gave me an excuse to go hide in a quiet room for 90 minutes :-)
Comment #19
jdlind38 commentedWill this feature be in the next release?
Comment #20
agentrickardYes. It is already in HEAD.
Comment #21
mitchell commentedI 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.
Comment #22
agentrickard@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.
Comment #23
mitchell commented@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.
Comment #24
dave reidSome 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.
Comment #25
dave reidcopy/paste errors with the D7 patch
Comment #26
dave reidAdding tag
Comment #27
agentrickardThe 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.
Comment #28
dave reidIf 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.
Comment #29
dave reidFixed error with 'Current domain' name being used on [default-domain:?] tokens.
Comment #30
agentrickardCommitted 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.
Comment #31
dave reidI'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.
Comment #32
dave reidI'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.
Comment #33
agentrickardCommitted to 6.x
Comment #34
agentrickardCommitted to 7.x.2.