Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-02-05 17:03:24

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#2 2010-02-05 20:48:05

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

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

#3 2010-02-05 21:16:42

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#4 2010-10-03 06:19:21

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#5 2010-10-03 18:47:41

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

Board footer

Powered by FluxBB