function module_builder_generate_module in Module Builder 6.2
Same name and namespace in other branches
- 7 includes/generate.inc \module_builder_generate_module()
Generate module code.
Parameters
$module_data: An associative array of data for the module, passed by reference so data on generated files can be added. The keys can *mostly* be taken straight from form values. They are as follows:
- 'module_root_name'
- 'module_readable_name'
- 'module_short_description'
- 'module_help_text'
- 'hooks': An associative array whose keys are full hook names (eg 'hook_menu'), where requested hooks have a value of TRUE. Unwanted hooks may also be included as keys provided their value is FALSE.
- 'module_dependencies': a string of dependencies, eg 'forum views'.
- 'module_package': the module package.
- 'module_files': added by this function. A flat array of filenames that have been generated.
$bare: If true, omit header and footers and output only hook code.
Return value
An array of code, indexed by filename. Eg, 'modulename.module' => CODE
3 calls to module_builder_generate_module()
- module_builder_build_module in drush/
module_builder.drush.inc - Generates and outputs module code.
- module_builder_page_generate in includes/
module_builder.pages.inc - page 2: generate code
- Xmodule_builder_page_module in ./
module_builder.module - Module form: 'module' step. Generate the module code.
File
- includes/
generate.inc, line 288 - Module builder code generating code.
Code
function module_builder_generate_module(&$module_data, $bare = FALSE) {
// Get a set of hook declarations and function body templates for the hooks we want.
// $hook_data is of the form:
// 'hook_foo' => array( 'declaration' => DATA, 'template' => DATA )
$hook_file_data = module_builder_get_templates($module_data);
if (is_null($hook_file_data)) {
return NULL;
}
// There must always be a MODULE.module file, even if there are no hooks to
// go in it.
// (Slight niggle: it gets put at the end :/)
$hook_file_data += array(
$module_data['module_root_name'] . '.module' => array(),
);
//print_r($module_data);
//dsm($hook_file_data);
// Iterate over our data array, because it's in a pretty order.
// by each needed file of code.
$module_code = array();
foreach ($hook_file_data as $filename => $hook_data) {
$class = module_builder_get_class('code');
$generator = new $class($module_data);
$generator->hook_data = $hook_data;
$generator->filename = $filename;
if ($bare) {
$code = $generator->code_body;
}
else {
$code = $generator
->build();
}
//dsm($code);
//print $code;
$module_code[$filename] = $code;
// Add the generated filename to the module data for the info generation to find.
$module_data['module_files'][] = $filename;
}
// foreach file
//print_r($module_data);
return $module_code;
}