Michael van Dam - 2003-11-19

I just wanted to run this by everyone for some feedback:

I think we all agree the idea of 'hooks' or 'plugins' is a very good one.  i.e. That you can write a module without ANY prior knowledge of e.g. the comments service, and if you place the appropriate *generic* hooks into your code, your module can magically have comments support if the admin installs the comments service.

Some things are clearly services in this respect.  E.g comments, ratings, notifications, a hit-counter, etc.  What is less clear is how to implement the 'display'.  In the modules and services thread, we mentioned a 'display hook' whereby each hooked service can send some output to the module to append e.g. at the end of a new article.  If you look around the web, you'll see some sites where e.g. ratings are built right into the content of the news article, and others where ratings is implemented as a separate "block".

Both options are reasonable (to me).  What is special about these types of "blocks" is that their content relates to the particular item (e.g. news article) being shown.  (Contrast this with a list of recent comments, most popular links, etc... which deal with many things and in theory across several modules.)  Other blocks might include:  print-this-page, related-items-by-keyword, related-items-by-category, this-page-also-available-in-language-xyz.  Should this all use the 'hooks' facility as well?  I think so.  It would be nice that you could have all this functionality automagically for every module.

So my question is essentially: how would we do something like this?  My suggestion as far as I've thought about it is to indeed implement these all as hooked services.  Thus when an item is retrieved from the database, the other data is automatically retrieved in as efficient a manner as possible (e.g. as part of the same query).  When the 'display hook' is called, each hooked services examines its configuration info.  If the admin has decide the service output should be "inline" then it is returned as XHTML from the call to the 'display hook' callback.  If the admin has decided the service output should be in a separate block, then the 'display hook' callback returns nothing.  When the pagebuilder/template-engine sees the block to be displayed, the service will already have retrieved the data (somehow this is stored by the service and it will know not to perform more queries while preparing its template) and it can be displayed in the block.

As usual for me, a lot of details are fuzzy, but the basic idea is allowing the admin to choose which services are 'hooked' to a particular module, and to configure whether the output should be inline into the module output (by returning XHTML generated by an internal service template) or whether it should be in a separately configurable block (the admin will have control over placement).  Is there a less complicated way to do or think about this?  Comments/suggestions?  Thanks!