Plugins and events
Plugins are PHP code blocks in MODx that, unlike snippets, are not called for execution from a resource or a template. Rather, plugins are executed on the triggering of certain events, when a resource is parsed, or during other internal processing. Every action in MODx, such as rendering a resource, or deleting a user from the system, will trigger a series of flags. Each flag is viewed as an event. For example, you have events such as:
OnDocFormPrerender
—triggered just before the resource is going to be renderedOnUserFormSave
—triggered just before the user's details are saved
There are many such events, and we will not describe each one of them in this chapter. Rather, we will discuss how to write plugins that are executed in response to specific events. We will also describe how to generate events even custom ones—when you are writing snippets.
We will start by first examining some plugins that should have been installed during the setup, and gradually move into creating...