Index: content.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.install,v retrieving revision 1.12 diff -u -r1.12 content.install --- content.install 19 Aug 2006 22:56:14 -0000 1.12 +++ content.install 13 Sep 2006 23:47:55 -0000 @@ -228,7 +228,7 @@ */ function content_update_8() { $ret = array(); - + switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': @@ -242,3 +242,23 @@ return $ret; } + +function content_update_9() { + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $ret[] = update_sql(' + INSERT INTO {node_type} + (type, name, description, help, has_title, title_label, has_body, body_label) + SELECT (type_name, label, description, help, 1, title_label, 0, "") FROM {node_type_content} + '); + break; + + case 'pgsql': + break; + } + + return $ret; +} Index: content.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.module,v retrieving revision 1.77 diff -u -r1.77 content.module --- content.module 20 Aug 2006 19:34:09 -0000 1.77 +++ content.module 13 Sep 2006 23:44:30 -0000 @@ -3,7 +3,7 @@ /** * @file - * Allows administrators to define new content types. + * Allows administrators to associate custom fields to content types. */ define(CONTENT_DB_STORAGE_PER_FIELD, 0); @@ -24,30 +24,6 @@ case 'admin/settings/modules#description': return t('CCK: Allows administrators to define new content types.'); } - - if (strpos($section, 'node/add') === 0) { - $types = content_types(); - foreach ($types as $type_name => $type) { - if ($section == 'node/add#' . $type_name) { - return t($types[$type_name]['description']); - } - if ($section == 'node/add/' . $type_name) { - return t($types[$type_name]['help']); - } - } - } -} - -/** - * Implementation of hook_perm(). - */ -function content_perm() { - $perms = array('administer content types'); - foreach (content_types() as $name => $type) { - $perms[] = 'create '. $name .' content'; - $perms[] = 'edit own '. $name .' content'; - } - return $perms; } /** @@ -58,90 +34,32 @@ $access = user_access('administer content types'); // Only include administrative callbacks if we are viewing an admin page. - if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'types') { + if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'types') { include_once(drupal_get_path('module', 'content') .'/content_admin.inc'); } if ($may_cache) { $items[] = array( - 'path' => 'admin/node/types', - 'title' => t('content types'), - 'callback' => '_content_admin_type_overview', - 'access' => $access, - ); - $items[] = array( - 'path' => 'admin/node/types/list', - 'title' => t('list'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, - ); - $items[] = array( - 'path' => 'admin/node/types/add', - 'title' => t('add content type'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('_content_admin_type_edit'), - 'access' => $access, - 'type' => MENU_LOCAL_TASK, - ); - $items[] = array( - 'path' => 'admin/node/types/fields', + 'path' => 'admin/content/types/fields', 'title' => t('fields'), 'callback' => '_content_admin_type_fields', 'access' => $access, 'type' => MENU_LOCAL_TASK, ); - - $types = content_types(); - foreach ($types as $type_name => $type) { - $items[] = array( - 'path' => 'node/add/'. $type_name, - 'title' => t($type['label']), - 'access' => user_access('create '. $type_name .' content'), - ); - } } else { - if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'types' && arg(3)) { + if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'types' && arg(3)) { $type = content_types(arg(3)); if ($type) { $items[] = array( - 'path' => 'admin/node/types/'. arg(3), - 'title' => t($type['label']), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('_content_admin_type_edit'), - 'access' => $access, - 'callback arguments' => array(arg(3)), - 'type' => MENU_CALLBACK, - ); - $items[] = array( - 'path' => 'admin/node/types/'. arg(3) .'/delete', - 'title' => t('delete'), - 'callback' => '_content_admin_type_delete', - 'access' => $access, - 'callback arguments' => array(arg(3)), - 'type' => MENU_CALLBACK, - ); - $items[] = array( - 'path' => 'admin/node/types/'. arg(3) .'/duplicate', - 'title' => t('duplicate'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('_content_admin_type_edit'), - 'access' => $access, - 'callback arguments' => array('', arg(3)), - 'type' => MENU_CALLBACK, - ); - - $items[] = array( - 'path' => 'admin/node/types/'. arg(3) .'/edit', - 'title' => t('edit'), + 'path' => 'admin/content/types/'. arg(3), 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, ); $items[] = array( - 'path' => 'admin/node/types/'. arg(3) .'/fields', + 'path' => 'admin/content/types/'. arg(3) .'/fields', 'title' => t('manage fields'), 'callback' => '_content_admin_field_overview', 'access' => $access, @@ -150,7 +68,7 @@ 'weight' => 1, ); $items[] = array( - 'path' => 'admin/node/types/'. arg(3) .'/add_field', + 'path' => 'admin/content/types/'. arg(3) .'/add_field', 'title' => t('add field'), 'callback' => '_content_admin_field_add', 'access' => $access, @@ -159,10 +77,9 @@ 'weight' => 2, ); - if (arg(4) == 'fields' && arg(5) - && isset($type['fields'][arg(5)])) { + if (arg(4) == 'fields' && arg(5) && isset($type['fields'][arg(5)])) { $items[] = array( - 'path' => 'admin/node/types/'. arg(3) .'/fields/'. arg(5), + 'path' => 'admin/content/types/'. arg(3) .'/fields/'. arg(5), 'title' => t($type['fields'][arg(5)]['widget']['label']), 'callback' => 'drupal_get_form', 'access' => $access, @@ -170,11 +87,11 @@ 'type' => MENU_CALLBACK, ); $items[] = array( - 'path' => 'admin/node/types/'. arg(3) .'/fields/'. arg(5) .'/remove', + 'path' => 'admin/content/types/'. arg(3) .'/fields/'. arg(5) .'/remove', 'title' => t('remove field'), - 'callback' => '_content_admin_field_remove', + 'callback' => 'drupal_get_form', 'access' => $access, - 'callback arguments' => array(arg(3), arg(5)), + 'callback arguments' => array('_content_admin_field_remove', arg(3), arg(5)), 'type' => MENU_CALLBACK, ); } @@ -187,45 +104,7 @@ } /** - * Implementation of hook_node_info(). - */ -function content_node_info() { - $types = array(); - foreach (content_types() as $name => $type) { - $types[$name] = array( - 'name' => t($type['label']), - 'module' => 'content', - 'description' => $type['description'], - 'help' => $type['help'], - 'has_title' => TRUE, - 'title_label' => $type['title_label'], - 'has_body' => FALSE, - 'locked' => TRUE, - ); - } - return $types; -} - -/** - * Implementation of hook_access(). - */ -function content_access($op, $node) { - global $user; - $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); - - if ($op == 'create') { - return user_access('create '. $type .' content'); - } - - if ($op == 'update' || $op == 'delete') { - if (user_access('edit own '. $type .' content') && ($user->uid == $node->uid)) { - return TRUE; - } - } -} - -/** - * Implementation of hook_load(). + * load data for a node type's fields. * * When loading one of the content.module nodes, we need to let each field handle * its own loading. This can make for a number of queries in some cases, so we @@ -255,25 +134,19 @@ } /** - * Implementation of hook_form(). + * create fields' form for a content type. * * Each field defines its own component of the content entry form, via its * chosen widget. */ -function content_form(&$node, &$param) { +//function content_form(&$node, &$param) { +function content_form(&$node) { + drupal_set_message('content_form'); $form = array(); $type = content_types($node->type); // Set form parameters so we can accept file uploads. $form['#attributes'] = array("enctype" => "multipart/form-data"); - - $form['title'] = array( - '#type' => 'textfield', - '#title' => t($type['title_label']), - '#required' => TRUE, - '#default_value' => $node->title, - ); - _content_widget_invoke('prepare form values', $node); $form = array_merge($form, _content_widget_invoke('form', $node)); @@ -281,7 +154,7 @@ } /** - * Implementation of hook_validate(). + * #validate form callback to handle node type fields. * * Both widgets and fields have a chance to raise error flags when a node is * being validated. @@ -294,7 +167,7 @@ } /** - * Implementation of hook_submit(). + * submit form callback for node type fields. * * At submit time, the widget does whatever data massaging is necessary so that * the field has the content in the expected format and can commit the changes @@ -308,7 +181,7 @@ } /** - * Implementation of hook_insert(). + * insert node type fields. */ function content_insert(&$node) { _content_field_invoke('insert', $node); @@ -316,7 +189,7 @@ } /** - * Implementation of hook_update(). + * update node type fields. */ function content_update(&$node) { _content_field_invoke('update', $node); @@ -325,7 +198,7 @@ } /** - * Implementation of hook_delete(). + * delete node type fields; */ function content_delete(&$node) { _content_field_invoke('delete', $node); @@ -334,31 +207,82 @@ } /** - * Implementation of hook_view(). + * delete node type fields for a revision. + */ +function content_delete_revision(&$node) { + if (content_types($node->type)) { + _content_field_invoke('delete revision', $node); + _content_field_invoke_default('delete revision', $node); + cache_clear_all('content:'. $node->nid .':'. $node->vid); + } +} + +/** + * generate field render arrays. */ function content_view(&$node, $teaser = FALSE, $page = FALSE) { if ($node->in_preview) { _content_widget_invoke('process form values', $node); } - $node->body = implode('', _content_field_invoke('view', $node, FALSE, $page)); - $node->teaser = implode('', _content_field_invoke('view', $node, TRUE, $page)); - $node->readmore = (strlen($node->teaser) < strlen($node->body)); + $node->content['cck-fields'] = array ( + '#value' => implode('', _content_field_invoke('view', $node, $teaser, $page)), + '#weight' => 1, + ); } /** * Implementation of hook_nodeapi(). * * When a revision is deleted, make sure the appropriate cache item is cleared. + * @todo: deprecate op==validate & op==submit in favor of form callbacks. */ function content_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { + case 'load': + return content_load($node); + + case 'form': + return content_form($node); + + case 'validate': + content_validate($node); + break; + + case 'submit': + content_submit($node); + break; + + case 'insert': + content_insert($node); + break; + + case 'update': + content_update($node); + break; + + case 'delete': + content_delete($node); + break; + case 'delete revision': - if (content_types($node->type)) { - _content_field_invoke('delete revision', $node); - _content_field_invoke_default('delete revision', $node); - cache_clear_all('content:'. $node->nid .':'. $node->vid); - } + content_delete_revision($node); break; + + case 'view': + content_view($node, $teaser, $page); + break; + } +} + + +function content_form_alter($form_id, &$form) { + if (isset($form['type'])) { + $node = $form['#node']; + if ($form['type']['#value'] .'_node_form' == $form_id) { + drupal_set_message('merging forms'); + $content_form = content_form($node); + $form = array_merge($form, content_form($node)); + } } } @@ -514,23 +438,25 @@ $field_types = _content_field_types(); $return = array(); - foreach ($type['fields'] as $field) { - $node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); + if (count($type['fields'])) { + foreach ($type['fields'] as $field) { + $node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); - $module = $field_types[$field['type']]['module']; - $function = $module .'_field'; - if (function_exists($function)) { - $result = $function($op, $node, $field, $node_field, $teaser, $page); - if (is_array($result)) { - $return = array_merge($return, $result); - } - else if (isset($result)) { - $return[] = $result; + $module = $field_types[$field['type']]['module']; + $function = $module .'_field'; + if (function_exists($function)) { + $result = $function($op, $node, $field, $node_field, $teaser, $page); + if (is_array($result)) { + $return = array_merge($return, $result); + } + else if (isset($result)) { + $return[] = $result; + } } - } - if (isset($node->$field['field_name'])) { - $node->$field['field_name'] = $node_field; + if (isset($node->$field['field_name'])) { + $node->$field['field_name'] = $node_field; + } } } @@ -546,22 +472,24 @@ $field_types = _content_field_types(); $return = array(); - foreach ($type['fields'] as $field) { - $node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); + if (count($type['fields'])) { + foreach ($type['fields'] as $field) { + $node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array(); - $db_info = content_database_info($field); - if (count($db_info['columns'])) { - $result = content_field($op, $node, $field, $node_field, $teaser, $page); - if (is_array($result)) { - $return = array_merge($return, $result); - } - else if (isset($result)) { - $return[] = $result; + $db_info = content_database_info($field); + if (count($db_info['columns'])) { + $result = content_field($op, $node, $field, $node_field, $teaser, $page); + if (is_array($result)) { + $return = array_merge($return, $result); + } + else if (isset($result)) { + $return[] = $result; + } } - } - if (isset($node->$field['field_name'])) { - $node->$field['field_name'] = $node_field; + if (isset($node->$field['field_name'])) { + $node->$field['field_name'] = $node_field; + } } } @@ -717,10 +645,10 @@ $info['fields'][$field['field_name']] = $field; } - $type_result = db_query('SELECT * FROM {node_type_content} nt ORDER BY nt.type_name ASC'); + $type_result = db_query('SELECT * FROM {node_type} nt ORDER BY nt.type ASC'); while ($type = db_fetch_array($type_result)) { $type['fields'] = array(); - $field_result = db_query("SELECT nfi.field_name, nfi.weight, nfi.label, nfi.widget_type, nfi.widget_settings, nfi.description FROM {node_field_instance} nfi WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type['type_name']); + $field_result = db_query("SELECT nfi.field_name, nfi.weight, nfi.label, nfi.widget_type, nfi.widget_settings, nfi.description FROM {node_field_instance} nfi WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type['type']); while ($field = db_fetch_array($field_result)) { // Overwrite global field information with specific information $field = array_merge($info['fields'][$field['field_name']], $field); @@ -736,11 +664,11 @@ unset($field['label']); $field['widget']['description'] = $field['description']; unset($field['description']); - $field['type_name'] = $type['type_name']; + $field['type_name'] = $type['type']; $type['fields'][$field['field_name']] = $field; } - $info['content types'][$type['type_name']] = $type; + $info['content types'][$type['type']] = $type; } cache_set('content_type_info', serialize($info), CACHE_PERMANENT); @@ -783,7 +711,7 @@ $columns = module_invoke($module, 'field_settings', 'database columns', $field); $db_info = array(); - + if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) { $db_info['table'] = 'node_data_'. $field['field_name']; } Index: content_admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_admin.inc,v retrieving revision 1.21 diff -u -r1.21 content_admin.inc --- content_admin.inc 20 Aug 2006 19:34:09 -0000 1.21 +++ content_admin.inc 13 Sep 2006 23:42:56 -0000 @@ -8,32 +8,6 @@ /** - * Menu callback; presents a listing of content types. - */ -function _content_admin_type_overview() { - $types = content_types(); - - $header = array(t('Label'), t('Name'), t('Description'), array('data' => t('Operations'), 'colspan' => 3)); - $rows = array(); - foreach ($types as $type) { - $row = array(); - $row[] = l(t($type['label']), 'admin/node/types/'. $type['type_name'] .'/fields'); - $row[] = $type['type_name']; - $row[] = $type['description']; - - $row[] = l(t('edit'), 'admin/node/types/'. $type['type_name']); - $row[] = l(t('duplicate'), 'admin/node/types/'. $type['type_name'] .'/duplicate'); - $row[] = l(t('delete'), 'admin/node/types/'. $type['type_name'] .'/delete'); - - $rows[] = $row; - } - - $output = theme('table', $header, $rows); - - return $output; -} - -/** * Menu callback; lists all defined fields for quick reference. */ function _content_admin_type_fields() { @@ -61,172 +35,13 @@ return $output; } -/** - * Menu callback; handles the editing of a content type. - */ -function _content_admin_type_edit($type_name = '', $original_type_name = '') { - $types = content_types(); - if (isset($types[$type_name])) { - $type = $types[$type_name]; - } - else { - if (isset($types[$original_type_name])) { - $type = $types[$original_type_name]; - } - else { - $type = array(); - $type['label'] = ''; - $type['description'] = ''; - $type['help'] = ''; - $type['title_label'] = 'Title'; - } - } - - $form = array(); - $form['label'] = array( - '#title' => t('Label'), - '#type' => 'textfield', - '#default_value' => $type['label'], - '#description' => t('The human-readable name of this content type.'), - '#required' => TRUE, - ); - $form['description'] = array( - '#title' => t('Description'), - '#type' => 'textarea', - '#default_value' => $type['description'], - '#rows' => 10, - '#description' => t('A brief description of the content type.'), - '#required' => FALSE, - ); - $form['help'] = array( - '#title' => t('Help text'), - '#type' => 'textarea', - '#default_value' => $type['help'], - '#rows' => 10, - '#description' => t('Instructions to present to the user when adding new content of this type.'), - '#required' => FALSE, - ); - $form['title_label'] = array( - '#title' => t('Title field label'), - '#type' => 'textfield', - '#default_value' => $type['title_label'], - '#description' => t('The label for the title field.'), - '#required' => TRUE, - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Save content type'), - ); - $form['type_name'] = array( - '#type' => 'value', - '#value' => $type_name, - ); - $form['original_type_name'] = array( - '#type' => 'value', - '#value' => $original_type_name, - ); - return $form; -} - -/** - * Save a content type after editing. - */ -function _content_admin_type_edit_submit($form_id, $form_values) { - $types = content_types(); - if (!isset($types[$form_values['type_name']])) { - // Find a valid, computer-friendly type name. - $form_values['type_name'] = trim($form_values['label']); - $form_values['type_name'] = drupal_strtolower($form_values['type_name']); - $form_values['type_name'] = str_replace(array(' ', '-'), '_', $form_values['type_name']); - $form_values['type_name'] = preg_replace('/[^a-z0-9_]/', '', $form_values['type_name']); - $form_values['type_name'] = 'content_'. $form_values['type_name']; - $form_values['type_name'] = substr($form_values['type_name'], 0, 32); - if (isset($types[$form_values['type_name']])) { - $counter = 0; - do { - $new_name = substr($form_values['type_name'], 0, 30) .'_'. $counter++; - } while (isset($types[$new_name])); - $form_values['type_name'] = $new_name; - } - - db_query("INSERT INTO {node_type_content} (type_name, label, description, help, title_label) VALUES ('%s', '%s', '%s', '%s', '%s')", $form_values['type_name'], $form_values['label'], $form_values['description'], $form_values['help'], $form_values['title_label']); - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {node_". $form_values['type_name'] ."} ( - vid int unsigned NOT NULL default '0', - nid int unsigned NOT NULL default '0', - PRIMARY KEY (vid) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - break; - - case 'pgsql': - db_query("CREATE TABLE {node_". $form_values['type_name'] ."} ( - vid integer unsigned NOT NULL default '0', - nid integer unsigned NOT NULL default '0', - PRIMARY KEY (vid) - )"); - break; - } - } - else { - db_query("UPDATE {node_type_content} SET label = '%s', description = '%s', help = '%s', title_label = '%s' WHERE type_name = '%s'", $form_values['label'], $form_values['description'], $form_values['help'], $form_values['title_label'], $form_values['type_name']); - } - - if (isset($form_values['original_type_name'])) { - // Duplicate the field structure from the old content type. - db_query("INSERT INTO {node_field_instance} (field_name, type_name, weight, label, widget_type, widget_settings, description) SELECT field_name, '%s', weight, label, widget_type, widget_settings, description FROM {node_field_instance} WHERE type_name = '%s'", $form_values['type_name'], $form_values['original_type_name']); - } - - drupal_set_message(t('Saved content type %type.', array('%type' => $form_values['label']))); - - content_clear_type_cache(); - menu_rebuild(); - - return 'admin/node/types/'. $form_values['type_name']; -} - -/** - * Menu callback; delete a content type. - */ -function _content_admin_type_delete($type_name = '') { - $type = content_types($type_name); - - $form = array(); - $form['type_name'] = array('#type' => 'value', '#value' => $type_name); - return confirm_form('_content_admin_type_delete', $form, t('Are you sure you want to delete the content type %type?', array('%type' => $type['label'])), 'admin/node/types', t('If you have any content left in this content type, it will be permanently deleted. This action cannot be undone.'), t('Delete'), t('Cancel')); -} - -/** - * Delete a content type. - */ -function _content_admin_type_delete_submit($form_id, $form_values) { - $type = content_types($form_values['type_name']); - - if ($type && $form_values['confirm']) { - // Delete all nodes of this content type. - $result = db_query("SELECT nid FROM {node} WHERE type = '%s'", $form_values['type_name']); - while ($node = db_fetch_object($result)) { - node_delete($node->nid); - } - db_query("DELETE FROM {node_field_instance} WHERE type_name = '%s'", $form_values['type_name']); - db_query("DELETE FROM {node_type_content} WHERE type_name = '%s'", $form_values['type_name']); - - db_query("DROP TABLE {node_". $form_values['type_name'] ."}"); - - drupal_set_message(t('Deleted content type %type.', array('%type' => $type['label']))); - content_clear_type_cache(); - return 'admin/node/types'; - } -} - /** * Menu callback; presents a listing of fields for a content type. */ function _content_admin_field_overview($type_name) { $type = content_types($type_name); + $field_types = _content_field_types(); $header = array(t('Label'), t('Name'), t('Type'), array('data' => t('Operations'), 'colspan' => 2)); @@ -244,8 +59,8 @@ $row[] = $field['field_name']; $row[] = $field_types[$field['type']]['label']; - $row[] = l(t('configure'), 'admin/node/types/'. $type_name .'/fields/'. $field['field_name']); - $row[] = l(t('remove'), 'admin/node/types/'. $type_name .'/fields/'. $field['field_name'] .'/remove'); + $row[] = l(t('configure'), 'admin/content/types/'. $type_name .'/fields/'. $field['field_name']); + $row[] = l(t('remove'), 'admin/content/types/'. $type_name .'/fields/'. $field['field_name'] .'/remove'); $rows[] = $row; } @@ -356,7 +171,7 @@ $output .= '
'. $field_type['label'] .'
'; foreach ($widget_types as $widget_name => $widget_type) { if (in_array($field_name, $widget_type['field types'])) { - $output .= '
'. form_render($form[$field_name .'-'. $widget_name]) .'
'; + $output .= '
'. drupal_render($form[$field_name .'-'. $widget_name]) .'
'; } } } @@ -396,7 +211,7 @@ drupal_set_message(t('Added field %label.', array('%label' => $prior_instance['label']))); content_clear_type_cache(); - return 'admin/node/types/'. $form_values['type_name'] .'/fields'; + return 'admin/content/types/'. $form_values['type_name'] .'/fields'; } /** @@ -438,7 +253,7 @@ } drupal_set_message(t('Created field %label.', array('%label' => $form_values['label']))); - return 'admin/node/types/'. $form_values['type_name'] .'/fields/'. $field_name; + return 'admin/content/types/'. $form_values['type_name'] .'/fields/'. $field_name; } /** @@ -447,7 +262,7 @@ function _content_admin_field_remove($type_name, $field_name) { $type = content_types($type_name); $field = $type['fields'][$field_name]; - + $form = array(); $form['type_name'] = array( '#type' => 'value', @@ -457,46 +272,47 @@ '#type' => 'value', '#value' => $field_name, ); - return confirm_form('_content_admin_field_remove', $form, t('Are you sure you want to remove the field %field?', array('%field' => $field['widget']['label'])), 'admin/node/types/'. $type_name .'/fields', t('If you have any content left in this field, it will be lost. This action cannot be undone.'), t('Remove'), t('Cancel')); + + $output = confirm_form($form, + t('Are you sure you want to remove the field %field?', array('%field' => $field['widget']['label'])), + 'admin/content/types/'. $type_name .'/fields', + t('If you have any content left in this field, it will be lost. This action cannot be undone.'), + t('Remove'), t('Cancel'), + '_content_admin_field_remove' + ); + + return $output; } /** * Remove a field from a content type. */ function _content_admin_field_remove_submit($form_id, $form_values) { - $type = content_types($form_values['type_name']); - $field = $type['fields'][$form_values['field_name']]; - $field_types = _content_field_types(); - $field_type = $field_types[$field['type']]; - $columns = module_invoke($field_type['module'], 'field_settings', 'database columns', $field); + db_query("DELETE FROM {node_field_instance} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); - if ($type && $field && $form_values['confirm']) { - db_query("DELETE FROM {node_field_instance} WHERE type_name = '%s' AND field_name = '%s'", $form_values['type_name'], $form_values['field_name']); - - drupal_set_message(t('Removed field %field from %type.', array('%field' => $field['widget']['label'], '%type' => $type['label']))); - $instances = db_result(db_query("SELECT COUNT(*) FROM {node_field_instance} WHERE field_name = '%s'", $form_values['field_name'])); - if ($instances == 1) { - if (!($field['multiple'])) { - // Multiple-valued fields are always stored per content type. - if (is_array($columns) && count($columns)) { - $new_field = $field; - $new_field['db_storage'] = CONTENT_DB_STORAGE_PER_CONTENT_TYPE; - db_query("UPDATE {node_field} SET db_storage = %d WHERE field_name = '%s'", CONTENT_DB_STORAGE_PER_CONTENT_TYPE, $form_values['field_name']); - content_alter_db_field($field, $columns, $new_field, $columns); - } - } - } - else if ($instances == 0) { + drupal_set_message(t('Removed field %field from %type.', array('%field' => $field['widget']['label'], '%type' => $type['label']))); + $instances = db_result(db_query("SELECT COUNT(*) FROM {node_field_instance} WHERE field_name = '%s'", $form_values['field_name'])); + if ($instances == 1) { + if (!($field['multiple'])) { + // Multiple-valued fields are always stored per content type. if (is_array($columns) && count($columns)) { - content_alter_db_field($field, $columns, array(), array()); + $new_field = $field; + $new_field['db_storage'] = CONTENT_DB_STORAGE_PER_CONTENT_TYPE; + db_query("UPDATE {node_field} SET db_storage = %d WHERE field_name = '%s'", CONTENT_DB_STORAGE_PER_CONTENT_TYPE, $form_values['field_name']); + content_alter_db_field($field, $columns, $new_field, $columns); } - db_query("DELETE FROM {node_field} WHERE field_name = '%s'", $form_values['field_name']); - - drupal_set_message(t('The field %field no longer exists in any content type, so it was deleted.', array('%field' => $field['widget']['label']))); } - content_clear_type_cache(); - return 'admin/node/types/'. $form_values['type_name'] .'/fields'; } + else if ($instances == 0) { + if (is_array($columns) && count($columns)) { + content_alter_db_field($field, $columns, array(), array()); + } + db_query("DELETE FROM {node_field} WHERE field_name = '%s'", $form_values['field_name']); + + drupal_set_message(t('The field %field no longer exists in any content type, so it was deleted.', array('%field' => $field['widget']['label']))); + } + content_clear_type_cache(); + return 'admin/content/types/'. $form_values['type_name'] .'/fields'; } @@ -669,7 +485,7 @@ } content_alter_db_field($prev_field, $prev_columns, $new_field, $new_columns); - return 'admin/node/types/'. $form_values['type_name'] .'/fields'; + return 'admin/content/types/'. $form_values['type_name'] .'/fields'; } @@ -789,6 +605,53 @@ foreach ($new_columns as $column => $attributes) { $column_name = $new_field['field_name'] .'_'. $column; if (!isset($previous_columns[$column]) || $previous_field['db_storage'] != $new_field['db_storage']) { + if (!db_table_exists($new_db_info['table'])) { + if ($new_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) { + if ($new_field['multiple']) { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + db_query("CREATE TABLE {". $new_db_info['table'] ."} ( + vid int unsigned NOT NULL default '0', + delta int unsigned NOT NULL default '0', + nid int unsigned NOT NULL default '0', + PRIMARY KEY (vid,delta) + ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); + break; + + case 'pgsql': + db_query("CREATE TABLE {". $new_db_info['table'] ."} ( + vid integer unsigned NOT NULL default '0', + delta integer unsigned NOT NULL default '0', + nid integer unsigned NOT NULL default '0', + PRIMARY KEY (vid,delta) + )"); + break; + } + + } + else { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + db_query("CREATE TABLE {". $new_db_info['table'] ."} ( + vid int unsigned NOT NULL default '0', + nid int unsigned NOT NULL default '0', + PRIMARY KEY (vid) + ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); + break; + + case 'pgsql': + db_query("CREATE TABLE {". $new_db_info['table'] ."} ( + vid integer unsigned NOT NULL default '0', + nid integer unsigned NOT NULL default '0', + PRIMARY KEY (vid) + )"); + break; + } + } // end: if ($new_field['multiple']) + } // end: if ($new_field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) + } content_db_add_column($new_db_info['table'], $column_name, $attributes['type'], $attributes); } else { --- content.info +++ content.info @@ -0,0 +1,3 @@ +; $Id$ +name = Content +description = Allows administrators to define new content types --- date.info +++ date.info @@ -0,0 +1,3 @@ +; $Id$ +name = Date Field +description = Defines a date/time field type. Note: Requires content.module. --- nodereference.info +++ nodereference.info @@ -0,0 +1,3 @@ +; $Id$ +name = Node Reference +description = Defines a field type for referencing one node from another. Note: Requires content.module. --- number.info +++ number.info @@ -0,0 +1,3 @@ +; $Id$ +name = Number +description = Defines numeric field types. Note: Requires content.module. --- optionwidgets.info +++ optionwidgets.info @@ -0,0 +1,3 @@ +; $Id$ +name = Option Widget +description = Defines selection, check box and radio button widgets for text and numeric fields. Note: Requires content.module, text.module and number.module. --- text.info +++ text.info @@ -0,0 +1,3 @@ +; $Id$ +name = Text +description = Defines simple text field types. Note: Requires content.module. --- userreference.info +++ userreference.info @@ -0,0 +1,3 @@ +; $Id$ +name = userreference +description = Defines a field type for referencing a user from a node. Note: Requires content.module. --- weburl.info +++ weburl.info @@ -0,0 +1,3 @@ +; $Id$ +name = WebURL +description = Defines simple weburl field types. Note: Requires content.module.