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.

Comments

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

joachim’s picture

+++ b/link.module
@@ -365,9 +365,32 @@ function _link_load($field, $item, $instance) {
+  $normal_path = drupal_get_normal_path($raw_path);
+  if ($item['url'] != $normal_path) {
+    $item['url'] = $normal_path;
+  }
+  else {
+    $normal_path = drupal_get_normal_path($item['url']);
+    if ($item['url'] != $normal_path) {
+      $item['url'] = $normal_path;
+    }
+  }

I don't understand what the 2nd pass if for here.

joachim’s picture

Also, I think this is incorrect:

  $raw_path = str_replace($base_url . base_path(), '', $item['url']);

For example, my local dev site is at http://localhost:8888/workshop/.

$base_url is http://localhost:8888/workshop
$base_url . base_path() is http://localhost:8888/workshop/workshop/

joachim’s picture

Status:Needs work» Needs review
StatusFileSize
new5.94 KB

Here's the patch from #20, rerolled, with in addition:
- field setting added
- tests added

I still don't understand the 2nd pass (see comment #22), or the business with the base path (comment #23) -- but it works :)

Note that for the field setting to work, I've changed the function signature of _link_process(). But as it begins with a _ it's considered an internal function to this module, therefore we're not breaking API.

DamienMcKenna’s picture

StatusFileSize
new2.72 KB
PASSED: [[SimpleTest]]: [MySQL] 1,297 pass(es).
[ View ]

I've rewritten the original patch to a) have an option to control whether it checks for a system path, b) rewrites the logic to be a little easier to follow. Also, comments.

DamienMcKenna’s picture

Status:Needs review» Needs work

Need to combine the two patches.

DamienMcKenna’s picture

Status:Needs work» Needs review
StatusFileSize
new4.04 KB
PASSED: [[SimpleTest]]: [MySQL] 1,297 pass(es).
[ View ]

I've merged my updated logic from #25 with joachim's patch.

joachim’s picture

Status:Needs review» Needs work

Patch 27 is missing the tests I added in patch 24.

(Also, how did you get the testbot to notice your patch?!)

DamienMcKenna’s picture

Status:Needs work» Needs review
StatusFileSize
new6.65 KB
PASSED: [[SimpleTest]]: [MySQL] 1,334 pass(es).
[ View ]

Doh! Here's the missing file too.

DamienMcKenna’s picture

I think I broke something when I was uploading #25 as it complained that you'd change the files list when I submitted the form.

joachim’s picture

Status:Needs review» Needs work
StatusFileSize
new6.62 KB

Here's an updated patch -- changes from #29 are just:

- whitespace in test file
- clearer messages in test assertions.

Setting to needs work, as:

+++ b/link.module
@@ -372,12 +380,57 @@ function _link_load($field, $item, $instance) {
+    // These variables are used to ensure

Not sure what this should say!

joep.hendrix’s picture

Great work!
I confirm that #31 works just fine.