Often times a user will just grab a url from wherever they are on the site and paste it in the field if they want to link to it instead of finding the drupal path (node/234, etc) to put in the field.

it would be great if there was some option to use something similar to pathologic.module or pathfilter which simply converts a regular link (the alias) to its internal equivalent if it exists.


rcross’s picture

I forgot to add - this is particularly useful when moving between a staging/production (or any other moving of url)

rcross’s picture

cross posted #836722: Support converting cck link paths to internal links with pathologic in case there is some synergy.

jcfiala’s picture

I agree, that would be interesting. Perhaps someone will give us a patch? :)

sos4nt’s picture

Status:Active» Needs review
new631 bytes

Here's a simple patch that converts an alias back to the system / internal path before saving:

my/alias/path -> node/2

DamienMcKenna’s picture

Status:Needs review» Needs work

The patch doesn't take into consideration the language argument of drupal_get_normal_path(), which could lead to problems.

DamienMcKenna’s picture

Version:6.x-2.x-dev» 7.x-1.x-dev
new815 bytes

Here's a version of the above patch for d7, while we're at it.

DamienMcKenna’s picture

Status:Needs work» Needs review

Lets get some feedback from people who run internationalized sites.

DamienMcKenna’s picture

Status:Needs review» Needs work

Another item that should be considered - should it be able to strip off the hostname & base_path too? E.g. if I paste in "http://www.example.com/newsite/products/green-shiny" should it be turn that into "node/123"?

rcross’s picture

stripping off the hostname & base_path were the main things I was thinking of when considering this. What i find is a very typical use is that an untrained (or lazy) content editor will just copy the url of the page they want from the url, and then paste it into the link field.

DamienMcKenna’s picture

Status:Needs work» Needs review
new1.45 KB
new1.14 KB

Try these, they first try stripping off the global $base_url & system base_path() and then check the path, then it tries the full path. I added the base_path check first as it would probably be the most common use case.

timofey’s picture

This is a must for the module!

#10 worked great - Please add it to the module.

mstrelan’s picture

#10 no longer applies to D7, and has some issues such as a missing brace. Update patch attached.

ranavaibhav’s picture

+1 for this feature.

askibinski’s picture

rooby’s picture

Status:Needs review» Needs work

The drupal 6 patch in #6 still applies with a little offset.

One problem with it is if the user enters a link to the sites home page it gets replaced with an empty string.
Then when you edit and save the page again you get issues.

This could be fixed if we were allowed relative links with a preceeding slash.

Anyway, this homepage case needs to be addressed in some way.

rooby’s picture

Maybe in that one case it should be replaced by <front> ?

seanB’s picture

The patch in #12 works for me! Thanks.

mori’s picture

An excellent solution in my opinion is the one of this module: https://drupal.org/project/universal_reference

This module more or less a combo of the link module and the node_reference module.
It creates a field type which may both refer to an external URL (if an http:// link is entered) or autocomplete on node titles, to refer to internal nodes.
You can also specify a custom title or use the referenced node title or URL as default title.

kay_v’s picture

Issue summary:View changes
Status:Needs work» Reviewed & tested by the community

The patch in #12 worked cleanly for me against 7.x-1.2 (last stable release). Will test against dev. It would be great to have this patch committed :)

ciss’s picture

Status:Reviewed & tested by the community» Needs work
new1.28 KB

Rerolled against HEAD (commit 7dc306c, 2014-05-12). I guess the only thing that's missing now is a configuration option.

jcfiala’s picture

I am keeping an eye on this issue. Please make sure that patches that are created continue to pass the tests in the module.