Link Replace 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:
- Machine name of the target content type — e.g. "link" (if your content type is called Link).
- Use the Token browser to select a field that contains the target URL, e.g. "[node:field_link]".
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.
ParentsSiblings- Kinpedia
- Brilliant Gallery
- Hypergraph
- TrailScout
- Google Analytics Counter
- PagePeeker Screenshots
- Google Analytics Referrer
- Drupal Performance Mantra: Crawl, Boost, Expire
- Puzzler
- Recacher
- reSmush.it image style optimizer
- Gatsby & Drupal: In Quest of an Ideal Coupling
ENGLISH ARTICLEOCTOBER 20, 2018 AT 01:46:40 UTC