0

If I create a hyperlink inside a text field (such as node body) with an internal path uri such as "node/1234" or "index.php?q=taxonomy/term/5678", then I can use an input filter such as pathologic to convert that uri at display-time to the preferred alias uri, such as "http://example.dev/path/to/my/content"

(I would consider this a more resilient way of storing content than using the full aliased uri)

However, I can't see an easy way for a non-technical user to find an internal path uri and paste it in. Is there any way to get drupal to spot when a user has inserted an alias-based link into the content, and convert it into an internal path uri before saving to the database? I know the menu module does this with links, using drupal_get_normal_path(), but can it be done for html links in the content? Ideally with an existing D7 module?

For example, content like <p>More info at <a href="http://example.dev/info">this link</a></p> would be converted to <p>More info at <a href="node/123">this link</a></p> before saving into storage.

Also, is there any existing online discussion about the advisability of this approach?

1 Answer 1

1

In terms of non-technical (which I read as custom development) solutions, what you're describing is one of the features of LinkIt.

Linkit provides an easy interface for internal and external linking with editors and fields by using an autocomplete field. Linkit links to nodes, users, managed files, terms and have basic support for all entities by default. Linkit has three major advantages over traditional linking

It provides a WYSIWYG toolbar button from which a user can paste a URL for embedding a link. Upon setting up a LinkIt profile for you input type, there's a Insert paths as setting with a Raw paths option that defaults the inserted link as Drupal's internal path.

4
  • Thanks, that's a useful approach to the problem. However, I suspect users who have found an existing page and want to link to it are more likely to want to just paste the link in, rather than try to search for an entity title that seems to match the page they're looking at. Are there any other solutions which could accept an input URI and convert it from eg "example.dev/link/to/content" to "/node/1234" ?
    – Chris
    Commented Nov 18, 2015 at 13:46
  • It might exist; I'm not sure. I would look through the d.o. projects under Filter/Editors to see if you can find it. If you do, let me know and I'll post it in my answer. If not, I can explain how it could be done with a custom input filter (it definitely can be done, but your question asked if it already exists).
    – Shawn Conn
    Commented Nov 18, 2015 at 23:29
  • Great, I was contemplating writing something like this if it doesn't exist.
    – Chris
    Commented Nov 20, 2015 at 11:50
  • I was thinking of using hook_field_attach_presave, similar domain processing to pathologic, and drupal_get_normal_path for URIs that look like they're internal. But if there are other ways of doing it, I'd be interested.
    – Chris
    Commented Nov 20, 2015 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.