A discussion of open source eLearning tools covering Moodle, Alfresco, Mahara, and Kaltura amongst other technologies. Posts range from interesting anecdotes and adventures, to practical tips, to big picture discussions of trends and learning theory.
Thursday, May 6, 2010
How to Create and Modify Moodle Filters
by Jonathan Moore Michael Churchward |May 2010| Moodle
In this article byJonathan MooreandMichael Churchward, authors ofMoodle 1.9 Extension Development, we will discuss the basic concepts of creating a Moodle filter, which includes:
How a filter works
Using the API to create filter code
How to use language files
How to create configuration settings
Moodle filters modify content from the database as it is output to the screen, thus adding function to the display. An example of this is the multimedia filter, which can detect references to video and audio files, and can replace them with a "mini-player" embedded in the content.
How a filter works
Before trying to build a filter, it would help to understand how it works. To begin with, any text written to the screen in Moodle should be processed through theformat_textfunction. The purpose of this function is to process the text, such that it is always safe to be displayed. This means making sure there are no security issues and that any HTML used contains only allowed tags.
Additionally, the output is run through thefilter_textfunction, and this is the function we are interested in. This function takes the text destined for the screen, and applies all enabled filters to it. The resulting text will be the result of all of these filters.
filter_textapplies each enabled filter to the text in the order defined in the filter configuration screen (shown in the following screenshot). The order is important; each filter will be fed the output of the previous filter's text. So it is always possible that one filter may change the text in a way that impacts the next filter.