Module.class.php
Module Development (Form Tools 3)
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.
<?php
namespace FormTools\Modules\MyModule;
use FormTools\Module as FormToolsModule;
class Module extends FormToolsModule
{
protected $moduleName = "My Module";
protected $author = "Your Name";
protected $authorEmail = "you@something.com";
protected $authorLink = "https://yoursite.com";
protected $version = "1.0.0";
protected $date = "2018-02-20";
protected $originLanguage = "en_us";
protected $cssFiles = array(
// list of CSS files to include here
);
protected $jsFiles = array(
// list of JS files to include here
);
protected $nav = array(
"module_name" => array("index.php", false),
"word_submenu" => array("submenu.php", true)
);
public function install($module_id)
{
return array(true, "");
}
public function uninstall($module_id)
{
return array(true, "");
}
public function upgrade($module_id, $old_module_version)
{
return array(true, "");
}
}
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
$moduleDesc
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
$authorLink
$version
$date
$originLanguage
en_us
by default.
$cssFiles
{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.
protected $cssFiles = array(
"{MODULEROOT}/styles/css1.css"
"{MODULEROOT}/styles/css2.css"
);
$jsFiles
$cssFiles
setting and offers the same placeholders.
$nav
"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:
protected $nav = array(
"module_name" => array("index.php", false),
"word_settings" => array("/settings/", true)
);
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.