Pepper Event Handlers and Methods
Now that we’ve gotten the Pepper properties out of the way, let’s take a look at the default methods and event handlers:
These default functions will be called directly by Mint in response to a particular event. Let’s go right down the list, in the order they are likely to be called.
onPepperLoad() event handler fires immediately after the
$Mint object is created as Mint loads all installed Pepper. It serves as a replacement for individual Pepper constructors. Because Mint manages loading Pepper data and preferences, and information about the Pepper and its panes are now inherited properties of the parent Pepper class, there’s not much left for this handler to do. May be useful down the road.
onUpdate() event handler fires when Mint is being updated. Could be used to allow a Pepper to support multiple versions of Mint with different feature sets.
update() method is called when Mint detects that the hard-coded version of a Pepper is greater than Mint’s internal version for a Pepper. Use to update existing Pepper preferences or data to be compatible with the current Mint and Pepper version. Return true on success
It is each Pepper’s responsibility to check compatibility with the server software and the installed version of Mint. This method should return an associative array. The first index,
isCompatible, should be a boolean indicating whether this Pepper is compatible or not. The second, optional index
explanation provides an upgrade or helpful message specific to the server software or current version of Mint as a formatted HTML string. Use HERE doc syntax for complex messages. (Please provide a helpful explanation with upgrade info if your Pepper is not compatible.)
onInstall() method is called once immediately after the Pepper has been installed. It is useful for notifying existing Pepper of the new Pepper’s presence—this method is not intended for adding columns or tables to the Mint database. Please use the
$moderate properties of the Pepper class to add columns or custom tables to the Mint Database.
$_SERVER variables. Any changes made to the Pepper’s data array in this event handler will be saved automatically. Values meant for the Mint visit table should be returned as an associative array with each column name as an index with the corresponding the value to be stored in that column as the value. This handler must return an array—even if it is just an empty array.
onDisplay() method. CSS should be included either via the
<link> tag or inline in a
onDisplay() event handler fires when Mint generates the display view or when an individual tab is loaded or refreshed. It should return the HTML contents of an individual tab. This handler is often a traffic handler, consisting of nested
switch statements that pass the HTML generation off to functions specific to each tab. While there is no requirement for this, these functions usually conform to the following naming convention,
getHTML_<PaneName><TabName>. This function may be omitted for pane-less Pepper.
<script> tag and is output after all panes but before the footer.
onDisplayPreferences() event handler fires when Mint generates the Preferences view. This handler should return an assoicative array (indexed by pane name) that contains the HTML contents of that pane’s preference. Preferences used by all panes in this Pepper should be indexed as
Global and appear first in the array. This function may be omitted if the Pepper doesn’t utilize preferences.
onSavePreferences() event handler fires after clicking the Done button in the Preferences view. This handler should validate any user input requested by the
onDisplayPreferences() handler and assign the validated input to the
$prefs property. This function may be omitted if the Pepper doesn’t utilize references.
onCustom() event handler fires when the
custom argument appears in the query string of a request or a form is posted with
MintPath set to “Custom”. The Pepper is responsible for providing additional variables and logic to handle those variables. The function can return anything or nothing—whatever is appropriate for its use. The
$data properties are automatically saved to the database by Mint after this handler is called.
onUninstall() method is a Pepper’s dying breath. Use it to notify other Pepper that it is being uninstalled (most useful for tandem preferences). Mint still handles uninstallation so database manipulation is unnecessary; use only for notification.