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.

Comments

fago’s picture

Perhaps 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.

mitchell’s picture

The developers of Pathauto might be able to help us make an include for paths and breadcrumbs.

fago’s picture

Make an include? What do you mean with that?

greggles’s picture

You 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.

mitchell’s picture

Title: How to properly use replacement patterns with path redirect action » Properly format paths in "path redirect" and "set breadcrumb" actions
Version: 6.x-1.0-beta5 » 6.x-1.x-dev
Component: Miscellaneous » Rules Engine
Category: support » feature

Pathauto'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.

fago’s picture

hm, 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.

fumbling’s picture

Thanks 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.

fago’s picture

php field? Of course you can also use the php-action: http://groups.drupal.org/node/10270/faq#php-action

mitchell’s picture

@fumbling: In the interest of comprehensiveness, could you please post your php code?

mitchell’s picture

Title: Properly format paths in "path redirect" and "set breadcrumb" actions » Use external method instead of rules_clean_path()
Status: Active » Postponed
Issue tags: +clean path
mitchell’s picture

Title: Use external method instead of rules_clean_path() » Use generic module instead of rules_clean_path()
mitchell’s picture

mitchell’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Status: Postponed » Active

Reopening 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.

fago’s picture

Title: Use generic module instead of rules_clean_path() » Add a setting for rules path cleaning callbacks

We have

  // @todo Add a setting for choosing path cleaning callbacks.
  $function = variable_get('rules_path_cleaning_callback', 'rules_path_default_cleaning_method');

now in rules_clean_path().

We should just add a setting for that to the general module settings.

amitaibu’s picture

1) 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().

amitaibu’s picture

Status: Active » Needs review
StatusFileSize
new805 bytes

And here's the patch.

amitaibu’s picture

StatusFileSize
new897 bytes

A bit better patch.

fago’s picture

Category: feature » task
Status: Needs review » Needs work

thanks, 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?

candelas’s picture

subscribe to be able to do this in rules :)
thanks for the module!

jared12’s picture

subscribe

fago’s picture

Title: Add a setting for rules path cleaning callbacks » Add ctools, pathauto rules path cleaning callbacks and settings
StatusFileSize
new2.52 KB

Started 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.

fago’s picture

StatusFileSize
new10.17 KB

next version, still not complete

* improved rules path cleaning to only clean actually inserted token values
* added pathauto support

todo: settings, strtolower for builtin/ctools.

fago’s picture

Status: Needs work » Fixed
StatusFileSize
new11.52 KB

ok, 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.

Status: Fixed » Closed (fixed)

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

tommyk’s picture

Status: Closed (fixed) » Needs work

I 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.

fago’s picture

Status: Needs work » Closed (fixed)

Please do not re-open closed issues.