Umil.module add
From phpBB Development Wiki
umil::module_add –– Adds a Module to the phpBB installation using the Umil Library.
Contents |
Description
string umil::module_add ( mixed $class [, mixed $parent [, array $data [, mixed $include_path ]]] )
Parameters
| Parameter | Required/Default | Usage |
|---|---|---|
| class | Required | The module class: acp, mcp, or ucp |
| parent | default 0 | The parent module_id or module_langname (0 for no parent) |
| data | default array() | An array of the data on the new module. This can be setup in two different ways. (see below) |
| include_path | default false | Optionally specify a custom include path (only works when using the automatic module add method) |
Return Values
Returns result or umil_end data
The $data array
Manually specifying module info
The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode.
$data = array(
'module_enabled' => 1,
'module_display' => 1,
'module_basename' => '',
'module_class' => $class,
'parent_id' => (int) $parent,
'module_langname' => '',
'module_mode' => '',
'module_auth' => '',
);
Automatically determining module info
The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file):
$data = array(
'module_basename' => 'asacp',
'modes' => array('settings', 'log', 'flag'),
);
Optionally you may omit 'modes' and it will insert all of the modules in that info file.
Examples
Example #1
Create a new module category within the ACP
$umil->module_add('acp', 'ACP_CAT_DOT_MODS', 'ACP_CAT_TEST_MOD');
Or you may specify it in an array in the first parameter:
$umil->module_add(array(
// Add a new category named ACP_CAT_TEST_MOD to ACP_CAT_DOT_MODS
array('acp', 'ACP_CAT_DOT_MODS', 'ACP_CAT_TEST_MOD'),
));
Example #2
This method utilises the Automatic method where we determine the module information from the module info file, so we only need to specify the module_basename, the module_parent (ACP_MESSAGES), and the module class (acp)
$umil->module_add('acp', 'ACP_MESSAGES', array('module_basename' => 'quicklinks'));
Or you may specify it in an array in the first parameter:
$umil->module_add(array(
array('acp', 'ACP_MESSAGES', array('module_basename' => 'quicklinks')),
));
Example #3
Use the automatic method, but install only specific modes from within that module info file. Like Example #2, You may also specify Modes.
$umil->module_add('acp', 'ACP_CAT_TEST_MOD', array(
'module_basename' => 'board',
'modes' => array('settings', 'features'),
));
Or as an array...
$umil->module_add(array(
// Add the settings and features modes from the acp_board module to the ACP_CAT_TEST_MOD category using the "automatic" method.
array('acp', 'ACP_CAT_TEST_MOD', array(
'module_basename' => 'board',
'modes' => array('settings', 'features'),
),
),
));
Example #4
Use the manual method where we do not need a module info file to specify the module data.
$umil->module_add('acp', 'ACP_CAT_TEST_MOD', array(
'module_basename' => 'board',
'module_langname' => 'ACP_AVATAR_SETTINGS',
'module_mode' => 'avatar',
'module_auth' => 'acl_a_board',
));
Or as an array...
$umil->module_add(array(
// Add the avatar mode from acp_board to the ACP_CAT_TEST_MOD category using the "manual" method.
array('acp', 'ACP_CAT_TEST_MOD', array(
'module_basename' => 'board',
'module_langname' => 'ACP_AVATAR_SETTINGS',
'module_mode' => 'avatar',
'module_auth' => 'acl_a_board',
),
),
));
Example #5 Combining calls
You can combine multiple calls to module add within a single call.
$umil->module_add(array(
// Add a new category named ACP_CAT_TEST_MOD to ACP_CAT_DOT_MODS
array('acp', 'ACP_CAT_DOT_MODS', 'ACP_CAT_TEST_MOD'),
// Add the settings and features modes from the acp_board module to the ACP_CAT_TEST_MOD category using the "automatic" method.
array('acp', 'ACP_CAT_TEST_MOD', array(
'module_basename' => 'board',
'modes' => array('settings', 'features'),
),
),
// Add the avatar mode from acp_board to the ACP_CAT_TEST_MOD category using the "manual" method.
array('acp', 'ACP_CAT_TEST_MOD', array(
'module_basename' => 'board',
'module_langname' => 'ACP_AVATAR_SETTINGS',
'module_mode' => 'avatar',
'module_auth' => 'acl_a_board',
),
),
));
See Also

