Reptag should be able to process non-node text easily

laken - May 13, 2009 - 23:23
Project:Rep[lacement]Tags
Version:HEAD
Component:Code / API
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:filter, reptag
Description

First let me say that this is a fantastic module which is making building our site much easier. The architecture is well thought out, the user interface is good, and it meets an important need in Drupal. Now for the request...

There are many places in Drupal where it would be really great to use Reptag which are currently impossible or require coding knowledge. For example, on our site we make extensive use of Panels and Views. View pages have optional textareas for page headers and footers which we use a lot. We need reptag replacements in these areas, but since they are not nodes, Reptags won't replace them. Also in Panels, we sometimes make a custom panel pane (similar to a custom block in Drupal core) and just enter some HTML text. We need Reptags replacements there too, but again since it's not a node, Reptags can't replace it by default. This also goes for custom blocks, and probably a lot of other places in Drupal where you can add text that isn't in a node.

I'm aware that I can call the reptag_replace() function from the theme layer to get replacements working on these non-node text pieces (and that's what I intend to do as a workaround) but eventually that will lead to a lot of hodgepodge custom theming for functionality that should be generalized.

However, all of these different non-node ways to add text to Drupal all support Drupal's filter system. So if Reptags had filter support, no theming hacks or custom coding would be necessary - you'd just enable the Reptag filter on the input formats you want, and you're done.

In this post, Thilo explains why Reptags isn't implemented with Drupal's filter system:

Reptag doesn't use hook_filter because of some characteristics of Drupal's filter system (there are other 'filters' which are not filters actually). Most important reason is that you don't have access to $node object using filters. hook_filter only passes the content/text/code. But without node object you cant have per-node (nid needed) or per-user (uid = author needed) operations/replacements.

I understand why the filter system is insufficient for these requirements and why you need to use hook_nodeapi here.

The second reason is that you can't have dynamic' content using filters, what means, you cant have content that changes everytime you view a node. Drupal's filter system runs when you save your node, reptag runs on every page view.

As far as I know, this is mistaken. Drupal's filter system does not run when you save a node (or other content), but rather when the content is output. Drupal never alters the original entered content - it is stored in the database as entered and filtered on output. Thus, it's totally possible to have dynamic replacements that change on every node view. Many existing filters work this way.

Since Thilo has said he is in the midst of a rewrite, it may be the perfect time to integrate filter support for Reptags. I would think it possible to implement hook_filter in Reptags as an addition to hook_nodeapi. Sure, you couldn't have all the nifty per-node and per-user replacements in those cases, but those are special cases. The benefits of making replacements easily available for non-node text are huge.

I'd really like to know what Thilo and the users think of this idea. If there's support for this, I may be able to help code it, but currently all my development is still on Drupal 5, so I'm not sure how much help that will be. I would definitely like to see this backported to the D5 branch if it is implemented.

#1

laken - May 13, 2009 - 23:27
Title:Implement hook_filter in Reptags so it can process text outside of nodes» Reptag should be able to process non-node text easily
 
 

Drupal is a registered trademark of Dries Buytaert.