Member:
Markus ⋅
Date: February 25, 2010, 07:43 AM
⋅ Subject: "Re: Tutorial: Creating data preprocessors for dynamic content"
The first segment was the easy version I meant for you to look at. Start digesting with that. =) The second segment was the intermediate version. This third segment is the version for people who want to start doing what I have been doing on a similar scale in customizing all aspects of module creation. Much of the below is something that's only really in use in some of the more advanced Wiccle modules, but the structures and the potential are identically present in iWiccle.
---
Advanced Dynamic Data Preprocessing and Postprocessing
If you want to go wild creating new dynamic processors into your iWiccle/Wiccle, this is an explanation of all available and possible data processor extension possibilities. The name of your processor function can be whatever you choose; I am referencing the default names I have been using so far. For example:
$core['module']['processor_post'] = "post_preprocessor";
So far the system primarily offers hooks for post-level dynamic data, as that's where most of the action is in individualizing blog posts from article posts, quiz posts, store item posts, and all other modules' posts that use the same symmetric data structure. You can apply the principles explained in this section to create new hooks in the system. (They will be addded in for all types of dynamic data in due course, as it becomes relevant in the course of our module development work.)
Module Preprocessors and Postprocessors
Whatever dynamic data is passed through class_modules.php latches on to the following processors. (You can look up the type's "method" in layout_grid.php -- if it's "get_elements", the data will be taking the correct route for your custom processors to intercept.)
Dynamic type preprocessor extensions are detected if they are named as "type_preprocess" (type being for example "category" for a prefix). The data available to preprocessors is the raw data coming out the database, before being touched by the system's default processors.
On the other hand, postprocessors latch on to the data after it's gone through the system hops, but hasn't gone to templating yet. Postprocessors are declared and detected under the variable $core['module']['type_postprocessor'] (type again being your type of choice).
Note: There is a slight bit of naming standardization to do in the preprocessor department, as some of them are from older versions of code. However, possible future changes will not affect your modifications, as they will only make the naming conventions more loose. Whenever substantial modifications are made and brought to our knowledge, we will start legacy aliasing to support multiple versions of modifications in one system.
Dynamic Data Form Preprocessors and Postprocessors
Data can also be processed in different ways as it goes through the methods in class_forms.php. These are the standard form processing extension declarations:
$core['module']['post_add_form_extension'] = "post_add_form_extension";
$core['module']['post_edit_form_extension'] = "post_edit_form_extension";
$core['module']['post_add_prepro_extension'] = "post_add_prepro_extension";
$core['module']['post_edit_prepro_extension'] = "post_edit_prepro_extension";
$core['module']['post_add_extension'] = "post_add_extension";
$core['module']['post_edit_extension'] = "post_edit_extension";
The post_add_form_extension and post_edit_form_extension extensions process the data before when the form is loaded for editing. The post_add_prepro_extension and the post_edit_prepro_extension parse the data after the form is submitted, and before the system parses the data (using class_elements.php insert data builders). The post_add_extension and post_edit_extension parse the submitted data after the system is done with its own processing and before it's inserted into the database.
Extending Dynamic Data Processor Hooks
If you want to create a new hook for checking data processor availability, you can use the following snippet for intercepting data and customize it for "parent", "category", or whatever other dynamic content you may need to process, at whatever point in the system flow.
if (!empty($core['module']['whatever_processor']))
{
$proc = new $core['module']['extension_class'];
if (method_exists($proc, $core['module']['whatever_processor']) === TRUE)
$data = $proc->$core['module']['whatever_processor']($data);
}