function Xmodule_builder_page_input in Module Builder 7
Same name and namespace in other branches
- 6.2 module_builder.module \Xmodule_builder_page_input()
Module form: 'input' step. Collect module data.
File
- ./
module_builder.module, line 181 - Builds scaffolding for custom modules.
Code
function Xmodule_builder_page_input($form, $form_values) {
_module_builder_check_settings();
// Include CSS for formatting
drupal_add_css(drupal_get_path('module', 'module_builder') . '/theme/module_builder.css');
// Module properties
$form['module_root_name'] = array(
'#type' => 'textfield',
'#title' => t('Machine-readable name'),
'#description' => t('This string is used to name the module files and to prefix all of your functions. This must only contain letters, numbers, and underscores, and may not start with a number.'),
'#required' => TRUE,
'#default_value' => 'mymodule',
);
$form['module_readable_name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('Name of your module as it will appear on the module admin page.'),
'#required' => TRUE,
'#default_value' => 'My Module',
);
$form['module_short_description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#description' => t('This text will appear in the module listing at <a href="!listing">%administer >> %build >> %modules</a>.', array(
'!listing' => url('admin/build/modules'),
'%administer' => 'Administer',
'%build' => 'Site building',
'%modules' => 'Modules',
)),
'#required' => TRUE,
'#default_value' => 'Does awesome things. Makes tea. Washes up. Favours of a personal nature.',
);
$form['module_help_text'] = array(
'#type' => 'textarea',
'#title' => t('Help text'),
'#description' => t('Help text (HTML) to appear in <a href="!help">%administer >> %help >> module_name</a> page.', array(
'!help' => url('admin/help'),
'%administer' => 'Administer',
'%help' => 'Help',
)),
);
$form['module_dependencies'] = array(
'#type' => 'textfield',
'#title' => t('Dependencies'),
'#description' => t('Space seperated list of other modules that your module requires.'),
);
$form['module_package'] = array(
'#type' => 'textfield',
'#title' => t('Package'),
'#description' => t('If your module comes with other modules or is meant to be used exclusively with other modules, enter the package name here. Suggested package names: Audio, Bot, CCK, Chat, E-Commerce, Event, Feed parser, Organic groups, Station, Video, Views and Voting.'),
);
// Check for custom hook_groups file, else use default
$path = drupal_get_path('module', 'module_builder');
if (file_exists($path . MODULE_BUILDER_CUSTOM_HOOK_GROUPS_TEMPLATE_PATH)) {
$template_file = file_get_contents($path . MODULE_BUILDER_CUSTOM_HOOK_GROUPS_TEMPLATE_PATH);
}
else {
$template_file = file_get_contents($path . MODULE_BUILDER_HOOK_GROUPS_TEMPLATE_PATH);
}
$form['hook_groups'] = array(
'#type' => 'fieldset',
'#title' => t('Hook groupings'),
'#description' => t('Selecting one or more of these features will automatically select appropriate hooks for you.'),
);
drupal_add_js($path . '/theme/module_builder.js');
// Get list of hook groups from installed template.
// Include generating component file.
module_builder_include('process');
$hook_groups = module_builder_parse_template($template_file);
foreach ($hook_groups as $hook_group_name => $hook_group) {
$hooks = explode("\n", $hook_group['template']);
$hook_array = array();
foreach ($hooks as $hook) {
$hook = trim($hook);
if (!empty($hook)) {
$hook_array[] = "'{$hook}'";
}
}
$form['hook_groups']['groups-' . $hook_group_name] = array(
'#type' => 'checkbox',
'#title' => $hook_group_name,
'#attributes' => array(
'onclick' => 'check_hooks(this, [' . implode(', ', $hook_array) . '])',
),
);
}
// Get list of hooks from downloaded documentation, organized in fieldsets.
$hook_groups = module_builder_get_hook_data();
if (!is_array($hook_groups) || !count($hook_groups)) {
form_set_error('hooks', t('No hooks were found. Please check the documentation path specified in the <a href="!settings">%administer >> %settings >> %modulebuilder</a> page.', array(
'!settings' => url('admin/settings/module_builder/update'),
'%administer' => 'Administer',
'%settings' => 'Site configuration',
'%modulebuilder' => "Module builder",
)));
}
else {
// Build hooks list
$form['hooks'] = array(
'#type' => 'checkboxes',
'#title' => t('Use the following specific hooks'),
);
foreach ($hook_groups as $hook_group => $hooks) {
$form['hooks'][$hook_group] = array(
'#type' => 'fieldset',
'#title' => $hook_group . ' hooks',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#theme' => 'module_builder_hook_list',
);
foreach ($hooks as $hook) {
$name = $hook['name'];
$desc = $hook['description'];
$form['hooks'][$hook_group][$name] = array(
'#type' => 'checkbox',
'#title' => str_replace('hook_', '', $name),
'#description' => $desc,
);
// Set some default hooks
if ($name == 'hook_menu') {
$form['hooks'][$hook_group][$name]['#default_value'] = 1;
}
}
// Sort list alphabetically
ksort($form['hooks'][$hook_group]);
}
/*
$form['download'] = array(
'#type' => 'checkbox',
'#title' => t('Automatically generate module file for download?'),
'#description' => t('When checked, this will automatically generate your module file for you and prompt your browser to download it.'),
'#default_value' => variable_get('module_builder_download', 1),
);
*/
$form['generate_module'] = array(
'#type' => 'submit',
'#name' => 'op',
'#value' => t('Generate'),
);
}
return $form;
}