internal links that use path with TinyMce

Last modified: March 31, 2008 - 11:25

Since it took me so long, i decided to write this down; perhaps it is of help for someone or someone else can comment a better method.

The problem: Internal drupal links like "node/123" in a textarea are not filtered to use the path, it would end up like this: "www.ursite.com/drupal/node/123", even if a path is set for that node. If i didn't wanted to use tinymce, this could have been easely cured by using a filter like pathfilter (http://drupal.org/project/pathfilter). But since I want to use tinymce, some fiddling around has to be done.

Here's what i did:

1. Installed Tinymce
2. Installed linktocontent -> http://drupal.org/project/linktocontent
3. installed pathfilter -> http://drupal.org/project/pathfilter
4. After setting it all up as described in the respective readme's, the only thing that i had to change was a small piece of code in linktocontent:
Find the function "insertAction" in "modules/tinymce/tinymce/jscripts/tiny_mce/plugins/linktomenu/jscripts/functions.js"

in that function change the line

// Create new anchor elements
var path = selectedNode.cells[0].firstChild.nodeValue;

to
// Create new anchor elements
var path = 'internal:' + selectedNode.cells[0].firstChild.nodeValue;

With a cleared cache this should function immediately. This will make all internal links use the format used for the pathfilter, which makes:

  "internal:admin/user"  ->  "http://example.com/mysite/admin/user"
  "internal:node/23"       ->  "http://example.com/mysite/node/23"
  "internal:node/99"       ->  "http://example.com/mysite/news/latest"

Side note: If you change the path to a node, the cache needs to be cleaned as well.

 
 

Drupal is a registered trademark of Dries Buytaert.