Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Callbacks for customizing queries
In thinking about the work Stef is doing on image_list
I have an eye toward obviating the need for image plugins, including mine, for all but highly-specialized cases. And it occurred to me that there is also a possible third way, adding plugin hooks to allow plugins to append to the WHERE
clause in image_list
, article
, and other such tags that select lists of stuff. You could get a custom version of image_list
with a tiny plugin; no need to duplicate the whole thing.
This goes approximately quintuple for article
and article_custom
. Over the years we’ve seen various article_custom
substitutes, which have generally had to duplicate doArticles()
(a very large function) and a couple of other core functions, often just to implement some very simple addition to core article
and/or article_custom
. The core article
tags have become very full-featured, but there are still cases where additional selection attributes are useful. For example, select only articles that have an assigned image (which, BTW, soo_article_filter allows). That one might actually be core-worthy, but the point is with the proposed callback it becomes super easy to add such features via a small plugin.
Any encouragement from the Dev Team and I would be happy to work on a patch for this.
Code is topiary
Offline
Re: Callbacks for customizing queries
Do you think you could devise a method which prevents plugins conflicts when more than one event handler chooses to provide additional WHEN clauses?
Offline
Re: Callbacks for customizing queries
Good point. I was thinking only of adding AND
clauses so that operator precedence with multiple plugins would not be an issue. I could see having two separate queues, one for simple AND
additions and another for a single OR
clause. This latter would always go at the end of the WHERE
statement, and could throw a warning if more than one plugin registers for it.
Code is topiary
Offline
Re: Callbacks for customizing queries
Patch and proof-of-concept plugin submitted to txp-dev list.
As submitted I envision two main ways of using this. One is to create drop-in replacements for core tags. With this usage the callback function is created, registered, and unregistered within the plugin tag function, so multiple plugins can coexist with no impact on each other.
The other usage is global. This is registered much like a traditional Txp callback, and will affect all uses of the core tag in question. In effect this allows a plugin author to globally add behaviors or alter defaults for a core tag. In this case it is up to plugin authors to follow some simple guidelines to avoid conflicts.
Code is topiary
Offline
Re: Callbacks for customizing queries
Version 0.2 of patch and plugin submitted. There is now an optional conflict resolution mechanism.
It has been interesting playing around with this. All in all I think it could be workable, but the question is whether it would be more sensible to break a larger tag function such as image_list
into smaller components. (There are reasons beside benefitting plugin authors that might make this a worthwhile change.)
Code is topiary
Offline