--- C:\Documents and Settings\Aldo\Local Settings\Temp\TCV3fd7.tmp\flexinode_admin.1.5.2.3.module Sat Apr 21 10:24:18 2007 +++ D:\drupal cvs\4.7.x\contributions\modules\flexinode\flexinode_admin.module Sat Apr 21 10:27:55 2007 @@ -20,15 +20,15 @@
'. t('For more information please read the configuration and customization handbook Flexinode page.', array('%flexinode' => 'http://www.drupal.org/handbook/modules/flexinode/')) .'
'; return $output; case 'admin/modules#description': return t('Allows administrators to define their own content types.'); - case 'admin/node/types': + case 'admin/settings/content-types/edit': return t('You may manage your own content types here. These will all have a "title" field to start off, and contain additional fields that you specify. Choose the "add content type" tab to add a new type. Make a selection below to edit an existing type or field. To delete a field or entire content type, first open the editing form for that field or type.'); - case 'admin/node/type': - return t('Once you create a content type here you will be able to add additional fields to it on the "content types" tab.'); + case 'admin/settings/content-types/flexinode/add': + return t('Once you create a content type here you will be able to add additional fields to it on the "edit content types" tab.'); } $output = ''; @@ -54,28 +54,36 @@ // admin menu items $items[] = array( - 'path' => 'admin/node/types', - 'title' => t('content types'), + 'path' => 'admin/settings/content-types/overview', + 'title' => t('list'), + 'access' => $admin_access, + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -1, + ); + $items[] = array( + 'path' => 'admin/settings/content-types/edit', + 'title' => t('edit content types'), 'callback' => 'flexinode_admin_page_admin', 'access' => $admin_access, - 'type' => MENU_LOCAL_TASK, + 'type' => MENU_CALLBACK, ); $items[] = array( - 'path' => 'admin/node/type', + 'path' => 'admin/settings/content-types/flexinode/add', 'title' => t('add content type'), 'callback' => 'flexinode_admin_content_type_form', 'access' => $admin_access, 'type' => MENU_LOCAL_TASK, + 'weight' => 1, ); $items[] = array( - 'path' => 'admin/node/type/delete', + 'path' => 'admin/settings/content-types/flexinode/delete', 'title' => t('delete content type'), 'callback' => 'flexinode_admin_confirm_delete_content_type', 'access' => $admin_access, 'type' => MENU_CALLBACK, ); $items[] = array( - 'path' => 'admin/node/field', + 'path' => 'admin/settings/content-types/flexinode/field', 'title' => t('edit fields'), 'callback' => 'flexinode_admin_admin_field', 'access' => $admin_access, @@ -93,51 +101,78 @@ return $items; } -/** - * MENU CALLBACKS - */ -/** - * Menu callback; presents an overview of all admin-defined content types. - */ -function flexinode_admin_page_admin($ctype_id = NULL) { - $content_types = flexinode_content_types(); - - $output = ''; +function flexinode_admin_form_alter($form_id, &$form) { + if(preg_match('/^flexinode-(\d*?)_node_settings$/',$form_id,$matches)>0) { + $ctype_id = $matches[1]; + $ctype = flexinode_load_content_type($ctype_id); - foreach ($content_types as $ctype) { - $ctype = flexinode_load_content_type($ctype->ctype_id); - $ctype->links[] = l(t('edit'), 'admin/node/type/'. $ctype->ctype_id); - $ctype->links[] = l(t('settings'), 'admin/settings/content-types/flexinode-'. $ctype->ctype_id); + $form['flexinode_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Content-type settings'), + '#weight' => -5, + ); + $form['flexinode_settings']['ctype_id'] = array( + '#type' => 'hidden', + '#value' => $ctype_id, + ); - $ctype->controls = flexinode_admin_field_select($ctype->ctype_id); + $form['flexinode_settings']['name'] = array( + '#type' => 'textfield', + '#title' => t('Content type name'), + '#default_value' => $ctype->name, + '#size' => 60, + '#maxlength' => 128, + '#required' => TRUE, + ); + $form['flexinode_settings']['description'] = array( + '#type' => 'textfield', + '#title' => t('Description'), + '#default_value' => $ctype->description, + '#size' => 60, + '#maxlength' => 128, + '#description' => t('A one-line description of the content type.'), + ); + $fields = array(); foreach ($ctype->fields as $field) { - $ctype->fieldlist[] = $field->label . ' (' . l(t('edit field'), 'admin/node/field/' . $field->field_id) .')'; + $fields[] = $field->label . ' (' . l(t('edit field'), 'admin/settings/content-types/flexinode/field/' . $field->field_id) .')'; } + $form['flexinode_settings']['fields']['current'] = array( + '#type' => 'markup', + '#value' => theme('item_list', $fields, t('Field list')), + ); - $output .= theme('flexinode_type', $ctype); - $first = FALSE; - } + $form['flexinode_settings']['fields']['field_type'] = array( + '#type' => 'select', + '#options' => flexinode_admin_field_select_options(), + ); + $form['flexinode_settings']['fields']['add'] = array( + '#type' => 'submit', + '#value' => t('Add field'), + ); - if (strlen($output) == 0) { - $output = ''. t('No flexinode content types have been defined. You can add a new content type.', array('%url' => url('admin/node/type'))) .'
'; - } - drupal_add_js('misc/collapse.js'); - return $output; + $form['buttons']['delete'] = array( + '#type' => 'submit', + '#value' => t('Delete'), + ); + + $form['#submit'] = array('flexinode_admin_content_type_form_submit' => array()) + (array)$form['#submit']; + $form['#validate'] = array('flexinode_admin_content_type_form_validate' => array()) + (array)$form['#validate']; + } } /** + * MENU CALLBACKS + */ + +/** * Menu callback; presents a form to edit an existing field in a content type. */ function flexinode_admin_admin_field($field_id = NULL) { $op = $_POST['op']; - $crumbs = drupal_get_breadcrumb(); - $crumbs[] = l('content types', 'admin/node/types'); - drupal_set_breadcrumb($crumbs); - switch ($op) { case t('Add field'): $field_id = $_POST['edit']['field_type']; @@ -146,15 +181,20 @@ case t('Confirm'): $field = flexinode_load_field($field_id); flexinode_admin_delete_field($field); - drupal_goto('admin/node/types/'. $field->ctype_id); + drupal_goto('admin/settings/content-types/flexinode-'. $field->ctype_id); break; case t('Delete'): $field = flexinode_load_field($field_id); $output = flexinode_admin_confirm_delete_field($field); break; - case t('More'): default: - $output = flexinode_admin_field_form($field_id); + if(is_numeric(arg(6))) { + $output = flexinode_admin_field_form(arg(5), arg(6)); + } elseif(is_numeric(arg(5))) { + $output = flexinode_admin_field_form(arg(5)); + } else { + drupal_not_found(); + } break; } @@ -281,29 +321,41 @@ * flexinode_content_type_form hook_submit callback function. */ function flexinode_admin_content_type_form_submit($form_id, $edit) { - if($_POST['op'] == t('Delete')) { - drupal_goto('admin/node/type/delete/'. $edit['ctype_id']); - } - if ($edit['ctype_id']) { $ctype_id = $edit['ctype_id']; + $field_type = $edit['field_type']; + $name = $edit['name']; + $description = $edit['description']; + foreach(array('ctype_id','field_type','name','description','add','delete') as $key) { + unset($edit[$key]); + } + + switch($_POST['op']) { + case t('Delete'): + drupal_goto('admin/settings/content-types/flexinode/delete/'. $ctype_id); + break; + case t('Add field'): + drupal_goto('admin/settings/content-types/flexinode/field/'.$field_type.'/'.$ctype_id); + break; + default: + if ($ctype_id) { $former_ctype = flexinode_load_content_type($ctype_id); - db_query("UPDATE {flexinode_type} SET name = '%s', description = '%s' WHERE ctype_id = %d", $edit['name'], $edit['description'], $ctype_id); + db_query("UPDATE {flexinode_type} SET name = '%s', description = '%s' WHERE ctype_id = %d", $name, $description, $ctype_id); - drupal_set_message(t('updated content type "%name".', array('%name' => $edit['name']))); + drupal_set_message(t('updated content type "%name".', array('%name' => $name))); } else { $ctype_id = db_next_id('{flexinode_ctype}'); - db_query("INSERT INTO {flexinode_type} (name, description, ctype_id) VALUES ('%s', '%s', %d)", $edit['name'], $edit['description'], $ctype_id); + db_query("INSERT INTO {flexinode_type} (name, description, ctype_id) VALUES ('%s', '%s', '%d')", $name, $description, $ctype_id); - drupal_set_message(t('created new content type "%name".', array('%name' => $edit['name']))); + drupal_set_message(t('created new content type "%name".', array('%name' => $name))); } // update the cached "create content" menu menu_rebuild(); - drupal_goto('admin/node/types/'. $ctype_id); + } } /** @@ -312,7 +364,7 @@ function flexinode_admin_confirm_delete_content_type($ctype_id) { if($_POST['op'] == t('Confirm')) { flexinode_admin_delete_content_type($ctype_id); - drupal_goto('admin/node/types'); + drupal_goto('admin/settings/content-types'); } $ctype = flexinode_load_content_type($ctype_id); @@ -324,7 +376,7 @@ '#type' => 'hidden', '#value' => $ctype->name, ); - return confirm_form('flexinode_confirm_delete_content_type', $form, t('Are you sure you want to delete the content type "%name"? All nodes of this type will be lost.', array('%name' => $ctype->name)), 'admin/node/type/'. $ctype_id); + return confirm_form('flexinode_confirm_delete_content_type', $form, t('Are you sure you want to delete the content type "%name"? All nodes of this type will be lost.', array('%name' => $ctype->name)), 'admin/settings/content-types/flexinode/add/'. $ctype_id); } /** @@ -332,6 +384,8 @@ */ function flexinode_admin_delete_content_type($ctype_id) { // TODO: Delete files as appropriate. + $ctype = flexinode_load_content_type($ctype_id); + db_query('DELETE FROM {flexinode_type} WHERE ctype_id = %d', $ctype_id); db_query('DELETE FROM {flexinode_field} WHERE ctype_id = %d', $ctype_id); $result = db_query("SELECT nid FROM {node} WHERE type = '%s'", 'flexinode-' . $ctype_id); @@ -340,7 +394,7 @@ } db_query("DELETE FROM {node} WHERE type = '%s'", 'flexinode-' . $ctype_id); - drupal_set_message(t('deleted content type')); + drupal_set_message(t('deleted content type "%type"',array('%type' => $ctype->name))); // update the cached "create content" menu menu_rebuild(); @@ -356,10 +410,11 @@ function flexinode_admin_field_form($field_id, $ctype_id = NULL) { if(is_numeric($field_id)) { $field = flexinode_load_field($field_id); + $ctype_id = $field->ctype_id; } else { $field->field_type = $field_id; - $ctype_id = $_POST['edit']['ctype_id']; + if(!is_numeric($ctype_id)) $ctype_id = $_POST['edit']['ctype_id']; } $form['label'] = array( '#type' => 'textfield', @@ -416,8 +471,6 @@ '#value' => $field->field_type, ); - $form['#action'] = url('admin/node/field/'. $field_id); - if ($field->field_id) { $form['delete'] = array( '#type' => 'submit', @@ -442,16 +495,16 @@ */ function flexinode_admin_field_form_submit($form_id, $edit) { flexinode_admin_save_field($edit); - drupal_goto('admin/node/types/'. $edit['ctype_id']); + drupal_goto('admin/settings/content-types/flexinode-'. $edit['ctype_id']); } /** * Builds and returns the field select form. */ function flexinode_admin_field_select($ctype_id = NULL) { - $form = $options = array(); + $form = array(); - $form['#action'] = url('admin/node/field'); + $form['#action'] = url('admin/settings/content-types/flexinode/field'); $form['#redirect'] = FALSE; $form['field_type'] = array( '#type' => 'select', @@ -512,7 +565,7 @@ * Generate a confirmation page prior to deleting a custom field. */ function flexinode_admin_confirm_delete_field($field) { - return confirm_form('delete_field', array(), t('Are you sure you want to delete field "%name"? All data in this field will be lost.', array('%name' => $field->label)), 'admin/node/field/'. $field->field_id); + return confirm_form('delete_field', array(), t('Are you sure you want to delete field "%name"? All data in this field will be lost.', array('%name' => $field->label)), 'admin/settings/content-types/flexinode/field/'. $field->field_id); } /** @@ -523,7 +576,7 @@ db_query('DELETE FROM {flexinode_field} WHERE field_id = %d', $field->field_id); db_query('DELETE FROM {flexinode_data} WHERE field_id = %d', $field->field_id); - drupal_set_message(t('deleted field %name', array('%name' => $field->label))); + drupal_set_message(t('deleted field "%name"', array('%name' => $field->label))); } @@ -531,7 +584,7 @@ * THEME FUNCTIONS **/ function theme_flexinode_type($type) { - $output = "