Link Replace Filter

An example implementation of the filterAn example implementation of the filter

A text filter providing the ability to replace URLs in free text links by URLs taken from another content type and field.

Use case

It is very advantageous not to enter external links directly into free texts (e.g. via a WYSIWYG). It is much more clever to enter references to nodes of another content type that contain the target URLs (e.g. in a Link module field). The reason is simple: links in a separate content type are concentrated in one place, so you can easily check / correct / manage them. And most importantly, you can re-use them: instead of entering the same link into two or more nodes, you enter references to the node that hold the URL — and if the URL needs any modification in the future, you can achieve it by changing one single node. The problem is that a link to a node renders the default view mode of the link node, meaning even though you want to link to https://drupal.org, the link will point to your own website's node that only contains the target URL. Some approaches, like Field Redirection or Rabbit Hole let you redirect any request for a node in a given content type to somewhere else. This is sub-optimal because while the direct linking is excellent if you need an external link in the body of an article, the downside is that users cannot ever access the link node directly (which can be useful if you have a link catalogue with tags, descriptions, related links, etc.) Other approaches will try to enter the target link directly into the text — but that, of course, beats the purpose of re-usability.

Solution

Enter Link Replace Filter, a lightweight link replacement system implemented as a text filter. Imagine you have a content type Link that contains a field (provided by the Link module) that contains the target URL. Go to the filters page (/admin/config/content/formats), edit one of the text formats (e.g. Full HTML), and enable the Link Replace Filter. In its settings you only need to enter two pieces of information:

Now, the next time you need to enter an external link in a text you are writing, just find and enter (e.g. using the excellent Linkit module) the link to your own node. The LRF module will make sure that when the text is displayed, the URLs (absolute or relative) to nodes of the content type you selected (link) will be replaced by the value of the (Link) field you specified.

More information

All comments and patches providing or leading to improvements are welcome in the issue queue. Accepting able co-maintainers with demonstrable vision for this module.

Tomáš Fülöpp
Sint-Agatha-Berchem, Belgium
October 19, 2013, October 23, 2013
Tomáš Fülöpp (2012)

Parents of this entryParents

Siblings of this entrySiblings

Related linksRelated links

Tagsmoduledrupalphpfilterurlanchorproject
LanguageENGLISH Content typeARTICLELast updateOCTOBER 20, 2018 AT 01:46:40 UTC