I'm trying to use the replacement patterns feature of the path redirect action, but fumbling. The main issue seems to be missing hyphens. When using the replacement pattern [node:title-raw], the URL ends up looking like this:
http://www.example.com/blah blah blah (no hyphens, so a broken URL)
What I need the URL to read is
http://www.example.com/blah-blah-blah
Any idea what replacement pattern, php snippet or other solution I need to make sure the hyphens appear? I noticed the same issue does not arise for the equivalent scenario in pathauto > automatic URL settings for some reason.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | rules_path_setting.patch | 11.52 KB | fago |
| #22 | rules_path_setting.patch | 10.17 KB | fago |
| #21 | rules_path_setting.patch | 2.52 KB | fago |
| #17 | ctools-cleanstring-1.patch | 897 bytes | amitaibu |
| #16 | ctools-cleanstring.patch | 805 bytes | amitaibu |
Comments
Comment #1
fagoPerhaps we should add some basic string operations? Then this would be possible to do without PHP. For now you can do it only by using the php input filter.
Comment #2
mitchell commentedThe developers of Pathauto might be able to help us make an include for paths and breadcrumbs.
Comment #3
fagoMake an include? What do you mean with that?
Comment #4
gregglesYou could use pathauto_cleanstring() to "clean" the string.
Ideally this would be abstracted out of Pathauto into a separate generalized module.
We live in a non-ideal world.
Comment #5
mitchell commentedPathauto's cleanstring() function can be found here:
@fago: this is the functionality I hope to see added to rules's path and breadcrumb features.
@fumbling: if you want this to remain a support request, I'll open a new issue.
Comment #6
fagohm, rules has already a similar function for that in the path module integration (rules_clean_path()) - so this is used when you use the action to create a path alias. However I'm not sure if we should use this when redirecting or setting breadcrumbs by default - as we would have to do it the same way when the path alias was create - else it fails. And if it fails, it fails even when the user manually enters the correct path. So this is no way to go.
Thus we could provide it as an option to the action or we provide another action, which takes a string and cleans its path. So one could manually apply it to a string variable and then use the string variable for redirecting.
Comment #7
fumbling commentedThanks for everyone's participation on this. I'm too green to follow the details, but appreciate the thoughts towards a solution. Meanwhile, looks like I might have approximated a solution w/ some php in the php field.
Comment #8
fagophp field? Of course you can also use the php-action: http://groups.drupal.org/node/10270/faq#php-action
Comment #9
mitchell commented@fumbling: In the interest of comprehensiveness, could you please post your php code?
Comment #10
mitchell commentedPostponed till #212208: allow other modules to affect strings (to help with custom accent/string replacement) and a new Clean Path module based on pathauto_cleanstring().
Comment #11
mitchell commentedComment #12
mitchell commentedMarked #522002: Use PathAuto punctuation settings for the create alias action as a duplicate.
Comment #13
mitchell commentedReopening since #212208: allow other modules to affect strings (to help with custom accent/string replacement) is fixed in pathauto (6.x and 7.x). see #545216: Fix pathauto_cleanalias() and pathauto_cleanstring(). Might as well move to 7.x.
Looking to the future, rules still does not offer robust, internal functionality to properly sanitize url aliases (see rules_clean_path). This would best be achieved by integrating with an external api to avoid code duplication. Currently, pathauto has a very proficient mechanism called hook_pathauto_clean_alias(), so that would be a good starting place for a common api. This api would be beneficial for rules as well as other modules that use the path system.
Comment #14
fagoWe have
now in rules_clean_path().
We should just add a setting for that to the general module settings.
Comment #15
amitaibu1) Since we are already checking for different modules in rules_path_default_cleaning_method() (i.e. transliteration)
2) Since most installation will have CTools
We can use ctools_cleanstring().
Comment #16
amitaibuAnd here's the patch.
Comment #17
amitaibuA bit better patch.
Comment #18
fagothanks, however we thing we should allow the user to choose the cleaning variant used. With the given patch enabling/disabling would suddenly influence generated paths, what wouldn't be clear to the user.
So let's expose a setting for this and the replacement char in the rules settings tab. I think it should default to the previous rules variant though, as this is always available + mention that paths are transliterated if the module is enabled.
Also, the ctools path-cleaning variant doesn't use the configured replacement char, does it?
Comment #19
candelas commentedsubscribe to be able to do this in rules :)
thanks for the module!
Comment #20
jared12 commentedsubscribe
Comment #21
fagoStarted working on that. Patch attached, but not yet finished. Let's also add pathauto integration too and expose settings like the replacement char and/or that people should install transliteration.
Comment #22
fagonext version, still not complete
* improved rules path cleaning to only clean actually inserted token values
* added pathauto support
todo: settings, strtolower for builtin/ctools.
Comment #23
fagook, I've completed this and committed it.
Instead of adding all the settings, I decided to suggest installing pathauto - which has sophisticated cleaning settings. Committed patch attached. Please test.
Comment #25
tommyk commentedI don't think this is actually working.
I've set up the URL path cleaning method to use Pathauto and set my Rule to do a Page redirect upon login to a path set as: path/[account:name]
I want the user to be redirected upon login to a URL of path/user-name, but instead they are redirected to a URL of path/User%20Name
I'm using the dev version of Rules and the stable version of Pathauto. I've also tried this setup with the CTools implementation without any luck, and with other tokens like [site:name], all with the same non-functional result.
Comment #26
fagoPlease do not re-open closed issues.