phpBB

Development Wiki

Difference between revisions of "Migrations/Tools/Module"

From phpBB Development Wiki

< Migrations‎ | Tools
m (Example)
m (Update layout of module code)
Line 58: Line 58:
 
     return array(
 
     return array(
 
         // Add a new category named ACP_CAT_TEST_MOD to ACP_CAT_DOT_MODS
 
         // Add a new category named ACP_CAT_TEST_MOD to ACP_CAT_DOT_MODS
         array('module.add', array('acp', 'ACP_CAT_DOT_MODS', 'ACP_CAT_TEST_MOD')),
+
         array('module.add', 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.
 
         // Add the settings and features modes from the acp_board module to the ACP_CAT_TEST_MOD category using the "automatic" method.
         array('module.add', array('acp', 'ACP_CAT_TEST_MOD', array(
+
         array('module.add', array(
 +
            'acp',
 +
            'ACP_CAT_TEST_MOD',
 +
            array(
 
                 'module_basename'      => 'acp_board',
 
                 'module_basename'      => 'acp_board',
 
                 'modes'                => array('settings', 'features'),
 
                 'modes'                => array('settings', 'features'),
Line 68: Line 75:
  
 
         // Add the avatar mode from acp_board to the ACP_CAT_TEST_MOD category using the "manual" method.
 
         // Add the avatar mode from acp_board to the ACP_CAT_TEST_MOD category using the "manual" method.
         array('module.add', array('acp', 'ACP_CAT_TEST_MOD', array(
+
         array('module.add', array(
 +
            'acp',
 +
            'ACP_CAT_TEST_MOD',
 +
            array(
 
                 'module_basename'  => 'acp_board',
 
                 'module_basename'  => 'acp_board',
 
                 'module_langname'  => 'ACP_AVATAR_SETTINGS',
 
                 'module_langname'  => 'ACP_AVATAR_SETTINGS',

Revision as of 20:39, 26 April 2013

The module tool allows you to add or remove modules in the ucp, mcp, or acp.

Note

The documentation is mostly copied from UMIL.module tools, since the functionality is identical.
Umil.module_add, Umil.module_remove

Add Module

Add a new module

array('module.add', array( mixed $class [, mixed $parent [, array $data [, mixed $include_path ]]] ))

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)

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'   => 'acp_asacp',
    
'modes'             => array('settings''log''flag'),
);

Optionally you may omit 'modes' and it will insert all of the modules in that info file.

Example

public function update_data()
{
    return array(
        
// Add a new category named ACP_CAT_TEST_MOD to ACP_CAT_DOT_MODS
        
array('module.add', 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('module.add', array(
            
'acp',
            
'ACP_CAT_TEST_MOD',
            array(
                
'module_basename'       => 'acp_board',
                
'modes'                 => array('settings''features'),
            ),
        )),

        
// Add the avatar mode from acp_board to the ACP_CAT_TEST_MOD category using the "manual" method.
        
array('module.add', array(
            
'acp',
            
'ACP_CAT_TEST_MOD',
            array(
                
'module_basename'   => 'acp_board',
                
'module_langname'   => 'ACP_AVATAR_SETTINGS',
                
'module_mode'       => 'avatar',
                
'module_auth'       => 'acl_a_board',
            ),
        )),
    ));
}

Remove Module

string umil::module_remove ( mixed $class [, mixed $parent [, array $module [, 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)
module default '' The module_id or module_langname of the module to remove (more information below)
include_path default false Optionally specify a custom include path (only works when using the automatic module add method)

The $module variable

Manually specifying module info

The "manual" way. When removing the module using the manual method you may specify a string (module_langname) or an integer (module_id)

Automatically determining module info

The "automatic" way. When removing the module using the automatic method you may use the same information sent through the $data array when using the automatic method of the module_add function. Just as with the automatic add method, this will automatically find the modules listed according to the given module_basename and modes from the _info file. For more information on this method see Umil.module_add#The_.24data_array

Example

public function update_data()
{
    return array(
        
// Remove the avatar mode from acp_board to the ACP_CAT_TEST_MOD category using the "manual" method.
        
array('module.remove', array('acp''ACP_CAT_TEST_MOD', array(
                
'module_basename'   => 'acp_board',
                
'module_langname'   => 'ACP_AVATAR_SETTINGS',
                
'module_mode'       => 'avatar',
                
'module_auth'       => 'acl_a_board',
            ),
        )),

        
// Remove the settings and features modes from the acp_board module to the ACP_CAT_TEST_MOD category using the "automatic" method.
        
array('module.remove', array('acp''ACP_CAT_TEST_MOD', array(
                
'module_basename'       => 'acp_board',
                
'modes'                 => array('settings''features'),
            ),
        )),

        
// Remove a new category named ACP_CAT_TEST_MOD to ACP_CAT_DOT_MODS
        
array('module.remove', array('acp''ACP_CAT_DOT_MODS''ACP_CAT_TEST_MOD')),
    ));
}