View source
<?php
function module_builder_module_builder() {
return array(
array(
'title' => t('Edit'),
'machine' => 'edit',
'callback' => 'module_builder_edit_form',
'default' => TRUE,
'submit' => 'module_builder_edit_form_submit',
),
array(
'title' => t('Menu'),
'machine' => 'menu',
'callback' => 'module_builder_menu_form',
),
array(
'title' => t('Node'),
'machine' => 'node',
'callback' => 'module_builder_node_form',
'export' => 'module_builder_node_export',
),
array(
'title' => t('Delete'),
'machine' => 'delete',
'callback' => 'module_builder_delete_form',
'submit' => 'module_builder_delete_form_submit',
'submit_button' => FALSE,
),
array(
'title' => t('Export'),
'machine' => 'export',
'callback' => 'module_builder_export_form',
'submit_button' => FALSE,
),
);
}
function module_builder_edit_form(&$form_state, $values, $mid) {
$form = array();
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('The external name of the module'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => isset($values->name) ? $values->name : '',
);
$form['machine'] = array(
'#type' => 'textfield',
'#title' => t('Machine-readable name'),
'#description' => t('Alpha-numeric characters and underscores only'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => isset($values->machine) ? $values->machine : '',
);
$form['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#description' => t('The description of the module'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => isset($values->description) ? $values->description : '',
);
module_builder_add_js('copy', 'makeUnderscore', '#edit-name', '#edit-machine');
return $form;
}
function module_builder_edit_form_submit($form, &$form_state) {
module_builder_default_submit($form, $form_state);
db_query("UPDATE {module_builder_basic} SET name = '%s' WHERE mid = %d", $form_state['values']['name'], $form_state['values']['mid']);
}
function module_builder_node_form(&$form_state, $values) {
if (isset($form_state['storage']['node_type_count']) && $form_state['storage']['node_type_count'] > 1 && isset($form_state['storage']['types']) && !empty($form_state['storage']['types'])) {
$node_type_count = $form_state['storage']['node_type_count'];
$types = $form_state['storage']['types'];
}
elseif (isset($values->types)) {
$node_type_count = count($values->types);
$types = $values->types;
}
else {
$node_type_count = 1;
}
$default_type = array(
'name' => '',
'machine' => '',
'description' => '',
'locked' => FALSE,
);
$form = array(
'#cache' => TRUE,
'#tree' => TRUE,
);
$form['integration'] = array(
'#type' => 'checkbox',
'#title' => t('Integrate with the node module'),
'#description' => t('If your module needs to interact with node types other than the ones it defines, check this'),
'#default_value' => isset($values->integration) ? (bool) $values->integration : FALSE,
);
$form['types'] = array(
'#type' => 'fieldset',
'#title' => t('Node types'),
'#description' => t('If the module defines any node types, fill out these values.'),
'#collapsible' => FALSE,
'#prefix' => '<div id="node-types-wrapper">',
'#suffix' => '</div>',
);
for ($delta = 0; $delta < $node_type_count; $delta++) {
if (!isset($types[$delta])) {
$type = $default_type;
}
else {
$type = $types[$delta] + $default_type;
}
$form['types'][$delta] = array(
'#type' => 'fieldset',
'#title' => t('Node type'),
'#collapsible' => TRUE,
);
$form['types'][$delta]['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('The external (not machine-readable) name of the content type.'),
'#default_value' => $type['name'],
);
$form['types'][$delta]['machine'] = array(
'#type' => 'textfield',
'#title' => t('Machine-readable name'),
'#description' => t('The machine-readable name of the content type.'),
'#default_value' => $type['machine'],
);
$form['types'][$delta]['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#description' => t('The description of the content type'),
'#default_value' => $type['description'],
);
$form['types'][$delta]['locked'] = array(
'#type' => 'checkbox',
'#title' => t('Locked'),
'#description' => t('If the content type is locked, the user can\'t modify any properties from the interface'),
'#default_value' => $type['locked'],
);
}
$form['types']['new'] = array(
'#type' => 'submit',
'#value' => t('New node type'),
'#submit' => array(
'_module_builder_node_submit',
),
'#ahah' => array(
'wrapper' => 'node-types-wrapper',
'path' => 'module_builder/js',
),
);
$form['#pre_render'][] = 'module_builder_node_after_build';
return $form;
}
function module_builder_node_after_build($form) {
foreach (element_children($form['types']) as $key) {
if (is_numeric($key)) {
module_builder_add_js('copy', 'makeUnderscore', '#' . $form['types'][$key]['name']['#id'], '#' . $form['types'][$key]['machine']['#id']);
}
}
return $form;
}
function _module_builder_node_submit($form, &$form_state) {
$form_state['storage']['node_type_count'] = count(element_children($form['types']));
$types = $form_state['values']['types'];
unset($types['new']);
$form_state['storage']['types'] = $types;
}
function module_builder_node_export($values, $module) {
$output = "";
if (isset($values->integration) && $values->integration == 1) {
$output .= module_builder_add_hook('nodeapi', $module);
}
if (isset($values->types) && count($values->types)) {
$output .= "/**\n * Implementation of hook_node_info().\n */\nfunction " . $module->machine . "_node_info() {\n return array(\n";
foreach ($values->types as $type) {
if (!empty($type['machine']) && $type['machine'] != "N") {
$output .= " '" . $type['machine'] . "' => array(,\n";
$output .= " 'name' => t('" . $type['name'] . "'),\n";
$output .= " 'module' => '" . $module->machine . "',\n";
$output .= " 'description' => t('" . $type['description'] . "'),\n";
$output .= " 'locked' => " . ($type['locked'] ? "TRUE" : "FALSE") . ",\n";
$output .= " ),\n";
}
}
$output .= " );\n}\n\n";
$output .= module_builder_add_hook('load', $module);
$output .= module_builder_add_hook('view', $module);
}
return $output;
}
function module_builder_menu_form(&$form_state, $values) {
if (isset($form_state['storage']['menu_item_count']) && $form_state['storage']['menu_item_count'] > 1 && isset($form_state['storage']['items']) && !empty($form_state['storage']['items'])) {
$menu_item_count = $form_state['storage']['menu_item_count'];
$items = $form_state['storage']['items'];
}
elseif (isset($values->items)) {
$menu_item_count = count($values->items);
$items = $values->items;
}
else {
$menu_item_count = 1;
}
$default_item = array(
'title' => '',
'path' => '',
'type' => 'Normal',
'callback' => '',
);
$form = array(
'#cache' => FALSE,
'#tree' => TRUE,
);
$form['items'] = array(
'#type' => 'fieldset',
'#title' => t('Menu items'),
'#description' => t('If the module defines any menu items, fill out these values.'),
'#collapsible' => FALSE,
'#prefix' => '<div id="menu-items-wrapper">',
'#suffix' => '</div>',
);
for ($delta = 0; $delta < $menu_item_count; $delta++) {
if (!isset($items[$delta])) {
$item = $default_item;
}
else {
$item = $items[$delta] + $default_item;
}
$form['items'][$delta] = array(
'#type' => 'fieldset',
'#title' => t('Menu item'),
'#collapsible' => TRUE,
);
$form['items'][$delta]['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#description' => t('The title of the menu item'),
'#default_value' => $item['title'],
);
$form['items'][$delta]['path'] = array(
'#type' => 'textfield',
'#title' => t('Path'),
'#description' => t('The path of the menu item, such as admin/build/modules'),
'#default_value' => $item['path'],
);
$form['items'][$delta]['type'] = array(
'#type' => 'select',
'#title' => t('Type'),
'#multiple' => FALSE,
'#options' => drupal_map_assoc(array(
'Normal',
'Tab',
'Default tab',
'Callback',
'Suggested item',
'#default_value' => $item['type'],
)),
);
$form['items'][$delta]['callback'] = array(
'#type' => 'textfield',
'#title' => t('Callback'),
'#description' => t('The title you enter here appears on the page.'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => $item['callback'],
);
}
$form['items']['new'] = array(
'#type' => 'submit',
'#value' => t('New menu item'),
'#submit' => array(
'_module_builder_menu_submit',
),
'#ahah' => array(
'wrapper' => 'menu-items-wrapper',
'path' => 'module_builder/js',
),
);
return $form;
}
function _module_builder_menu_submit($form, &$form_state) {
$form_state['storage']['menu_item_count'] = count(element_children($form['items']));
$items = $form_state['values']['items'];
unset($items['new']);
$form_state['storage']['items'] = $items;
}
function module_builder_export_form() {
$form = array();
if (!module_builder_archive_tar_enabled()) {
$form['note'] = array(
'#type' => 'item',
'#value' => t('Several file downloads have started. Please put them all in a single directory, %dir.', array(
'%dir' => unserialize(db_result(db_query("SELECT data FROM {module_builder_data} WHERE mid = '%d' AND type = '%s'", menu_get_object('module_builder', 4)->mid, 'edit')))->machine,
)),
);
$form['info_file'] = array(
'#value' => '<iframe src="' . url('module_builder/export/' . arg(4) . '/info') . '" width="1"></iframe>',
'#prefix' => '<div style="display: none">',
);
$form['module_file'] = array(
'#value' => '<iframe src="' . url('module_builder/export/' . arg(4) . '/module') . '" width="1"></iframe>',
'#suffix' => '</div>',
);
$form['enhanced'] = array(
'#type' => 'item',
'#value' => t('<strong>Note:</strong> For enhanced export capabilities, please download the <a href="!archive_tar">archive tar package</a> and put it in the module_builder directory.', array(
'!archive_tar' => 'http://dmitrizone.com/files/archive_tar.tgz',
)),
);
}
else {
}
return $form;
}