DOCUMENTATION

Search »

Module.class.php

Every module has a /code/Module.class.php file that contains the following:

  • High level information about your module: the author name, release date, module name and description (in your target language).
  • Installation, uninstallation and upgrade code, should your module require it.
  • Links to JS and CSS resources to get autoloaded in every one of your module pages (very handy!)
  • Defines the module navigation that'll appear in the interface when the user enters your module.
  • Contains any methods you need to expose to the outside world.

Let's start with an example.

Namespace

Form Tools module code is namespaced to prevent naming conflicts with other modules and the core code. The namespace takes the form: FormTools\Modules\YourModuleName. Form Tools folder conventions use underscores in folder names, so here your module folder would be named your_folder_name. If your folder is named svg_visualizations_lib your namespace needs to be FormTools\Modules\SvgVisualizationsLib. If you don't enter the namespace correctly, Form Tools will not be able to load or find your module.

The Module class

Take a look at global/code/Module.abstract.class.php. All Form Tools modules must extend this class - if you forget that step, Form Tools will not recognize your module. Also, note that your class name is always Module. You can define as many classes as you want, but the primary module class that Form Tools needs to see must be named Module.

Member variables

$moduleName
The name of your module in the language of your choice. You can also optionally provide a different name for people viewing the UI in different languages via your language files.
$moduleDesc
This has been removed in 3.1.5. You should now provide a one-liner description of your module in the module_description key in your language file. This will allow automatic localization of that value in the interface. See the Language files page for more info.
$author
Your name.
$authorLink
A link to whatever site is relevant for the author.
$version
The current module version. Please follow a simplified semver format of X.Y.Z, where X is the major release number, Y is the minor release and Z is for bug fix releases.
$date
The release date of the module version in YYYY-MM-DD format.
$originLanguage
The default language of the module. This maps to the filename of your language file. Set to en_us by default.
$cssFiles
This is a convenience option that lets you define CSS files to be included in all of your module pages. If you're not using it, just omit the member var altogether. It comes with a couple of handy placeholders:
  • {FTROOT} - the URL of your Form Tools folder, the same value as your $g_root_url value in your config.php file.
  • {FTVERSION} - your Form Tools version.
  • {MODULEVERSION} - your module version.
  • {MODULEROOT} - the URL to your module folder.
Example:
$jsFiles
This works exactly the same as the previous $cssFiles setting and offers the same placeholders.
$nav
This member variable contains your module navigation menu items. They are of the form: "lang_key_prop_name" => array("file name", true|false) where the last variable specifies whether the menu item should appear as a submenu item. Submenu items are styled differently depending on the theme, but they are usuall slightly indented and of a different colour.

Example:

Here, your language file contains at least two properties: "module_nav" and "word_settings" containing the appropriate strings.

Lastly, the install(), uninstall() and upgrade() methods contain whatever logic you need to execute for each lifecycle method. If you don't need them, you don't need to enter the method. See the following pages for more information, or just keep reading this section to continue learning about the basic anatomy of a module.