Index: fieldgroup.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/fieldgroup.install,v retrieving revision 1.31 diff -u -r1.31 fieldgroup.install --- fieldgroup.install 10 Jan 2008 18:47:51 -0000 1.31 +++ fieldgroup.install 11 Jan 2008 21:21:08 -0000 @@ -1,5 +1,5 @@ array( - 'type_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), - 'group_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), - 'label' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), - 'settings' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE), - 'weight' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0), + 'gid' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'description' => t('Primary Key: Unique group ID.') + ), + 'pid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + 'description' => t('The {content_group}.gid to which this group is a nested. If set to 0, this group is not a nested in an existing group.') + ), + 'type_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + 'description' => t('Content type the group is a member of, listed in {node_type}.type.') + ), + 'group_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '' + ), + 'label' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '' + ), + 'settings' => array( + 'type' => 'text', + 'size' => 'medium', + 'not null' => TRUE + ), + 'weight' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0 + ) ), - 'primary key' => array('type_name', 'group_name'), + 'indexes' => array( + 'pid' => array('pid'), + 'type_name' => array('type_name'), + 'group_name' => array('group_name') + ), + 'primary key' => array('gid') ); $schema['content_group_fields'] = array( 'fields' => array( - 'type_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), - 'group_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), - 'field_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), + 'type_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '' + ), + 'group_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '' + ), + 'field_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '' + ) ), - 'primary key' => array('type_name', 'group_name', 'field_name'), + 'primary key' => array('gid', 'field_name') ); return $schema; Index: fieldgroup.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cck/fieldgroup.module,v retrieving revision 1.66 diff -u -r1.66 fieldgroup.module --- fieldgroup.module 10 Jan 2008 20:15:52 -0000 1.66 +++ fieldgroup.module 11 Jan 2008 21:21:08 -0000 @@ -1,5 +1,5 @@ '; + foreach ($groups as $name => $item) { + $group_options[$item['gid']] = "{$item['label']} ({$item['gid']})"; + } + if ($action == 'add') { //adding a new one $group = array(); @@ -100,7 +105,7 @@ '#weight' => 10, ); } - elseif ($group = $groups[$group_name]) { + elseif ($group = $groups[$group_id]) { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), @@ -118,6 +123,12 @@ '#default_value' => isset($group['label']) ? $group['label'] : '', '#required' => TRUE, ); + $form['parent'] = array( + '#type' => 'select', + '#title' => t('Parent Group'), + '#default_value' => isset($group['pid']) ? $group['pid'] : '', + '#options' => $group_options + ); $form['settings']['#tree'] = TRUE; $form['settings']['form'] = array( '#type' => 'fieldset', @@ -159,8 +170,14 @@ foreach (array_merge(array_keys(_content_admin_display_contexts(CONTENT_CONTEXTS_SIMPLE)), array('label')) as $key) { $form['settings']['display'][$key] = array('#type' => 'value', '#value' => isset($group['settings']['display'][$key]) ? $group['settings']['display'][$key] : 'fieldset'); } - $form['weight'] = array('#type' => 'hidden', '#default_value' => isset($group['weight']) ? $group['weight'] : 0); - $form['group_name'] = array('#type' => 'hidden', '#default_value' => $group_name); + $form['weight'] = array( + '#type' => 'hidden', + '#default_value' => isset($group['weight']) ? $group['weight'] : 0 + ); + $form['group_id'] = array( + '#type' => 'hidden', + '#default_value' => isset($group['gid']) ? $group['gid'] : 0 + ); $form['#content_type'] = $content_type; $form['#group_action'] = $action; @@ -181,18 +198,18 @@ $content_type = $form['#content_type']; $action = $form['#group_action']; - if (!empty($form_values['group_name']) && $action == 'add') { + if (!empty($form_values['group_id']) && $action == 'add') { $groups = fieldgroup_groups($content_type['type']); - $group = $groups[$form_values['group_name']]; + $group = $groups[$form_values['group_id']]; - if (isset($group[$form_values['group_name']])) { + if (isset($group[$form_values['group_id']])) { form_set_error('group_name', t('The group name %name already exists.', array( - '%group_name' => $form_values['group_name']))); + '%group_name' => $form_values['group_id']))); } - if (!preg_match('!^[a-z0-9_]+$!', $form_values['group_name'])) { + if (!preg_match('!^[a-z0-9_]+$!', $form_values['group_id'])) { form_set_error('group_name', t('The group name %name is invalid.', array( - '%group_name' => $form_values['group_name']))); + '%group_name' => $form_values['group_id']))); } } } @@ -253,7 +270,7 @@ $groups_sorted = $data['groups_sorted']; } else { - $result = db_query("SELECT * FROM {". fieldgroup_tablename() ."} ORDER BY weight, group_name"); + $result = db_query('SELECT * FROM {'. fieldgroup_tablename() .'} ORDER BY weight, group_name'); $groups = array(); $groups_sorted = array(); while ($group = db_fetch_array($result)) { @@ -263,10 +280,10 @@ $groups_sorted[$group['type_name']][] = &$groups[$group['type_name']][$group['group_name']]; } //load fields - $result = db_query("SELECT nfi.*, ng.group_name FROM {". fieldgroup_tablename() ."} ng ". - "INNER JOIN {". fieldgroup_fields_tablename() ."} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name ". - "INNER JOIN {". content_instance_tablename() ."} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name ". - "WHERE nfi.widget_active = 1 ORDER BY nfi.weight"); + $result = db_query('SELECT nfi.*, ng.group_name FROM {'. fieldgroup_tablename() .'} ng '. + 'INNER JOIN {'. fieldgroup_fields_tablename() .'} ngf ON ngf.type_name = ng.type_name AND ngf.group_name = ng.group_name '. + 'INNER JOIN {'. content_instance_tablename() .'} nfi ON nfi.field_name = ngf.field_name AND nfi.type_name = ngf.type_name '. + 'ORDER BY nfi.weight'); while ($field = db_fetch_array($result)) { $groups[$field['type_name']][$field['group_name']]['fields'][$field['field_name']] = $field; } @@ -294,7 +311,7 @@ } function _fieldgroup_field_get_group($content_type, $field_name) { - return db_result(db_query("SELECT group_name FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); + return db_result(db_query('SELECT group_name FROM {'. fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND field_name = '%s'", $content_type, $field_name)); } /* @@ -303,7 +320,7 @@ function fieldgroup_form_alter(&$form, $form_state, $form_id) { if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { foreach (fieldgroup_groups($form['type']['#value']) as $group_name => $group) { - $form[$group_name] = array( + $fapi = array( '#type' => 'fieldset', '#title' => t($group['label']), '#collapsed' => $group['settings']['form']['style'] == 'fieldset_collapsed', @@ -312,9 +329,22 @@ '#description' => t($group['settings']['form']['description']), '#attributes' => array('class' => strtr($group['group_name'], '_', '-')), ); + if (isset($group['settings']['parent']) && arg(0) != 'admin') { + $form[$group['settings']['parent']][$group_name] = $fapi; + } + else { + $form[$group_name] = $fapi; + } + unset($fapi); + foreach ($group['fields'] as $field_name => $field) { if (isset($form[$field_name])) { - $form[$group_name][$field_name] = $form[$field_name]; + if (isset($group['settings']['parent']) && arg(0) != 'admin') { + $form[$group['settings']['parent']][$group_name][$field_name] = $form[$field_name]; + } + else { + $form[$group_name][$field_name] = $form[$field_name]; + } unset($form[$field_name]); } } @@ -487,13 +517,13 @@ function fieldgroup_node_type($op, $info) { if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { // update the tables - db_query("UPDATE {". fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); - db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); + db_query('UPDATE {'. fieldgroup_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); + db_query('UPDATE {'. fieldgroup_fields_tablename() ."} SET type_name='%s' WHERE type_name='%s'", array($info->type, $info->old_type)); cache_clear_all('fieldgroup_data', content_cache_tablename()); } elseif ($op == 'delete') { - db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type); + db_query('DELETE FROM {'. fieldgroup_tablename() ."} WHERE type_name = '%s'", $info->type); + db_query('DELETE FROM {'. fieldgroup_fields_tablename() ."} WHERE type_name = '%s'", $info->type); } } @@ -523,7 +553,7 @@ function fieldgroup_save_group($type_name, $group) { $groups = fieldgroup_groups($type_name); - if (!isset($groups[$group['group_name']])) { + if (!isset($group['group_id'])) { // Accept group name from programmed submissions if valid. if (!empty($group['group_name'])) { $group_name = $group['group_name']; @@ -544,15 +574,14 @@ } } } - db_query("INSERT INTO {". fieldgroup_tablename() ."} (type_name, group_name, label, settings, weight) - VALUES ('%s', '%s', '%s', '%s', %d)", $type_name, $group_name, $group['label'], serialize($group['settings']), $group['weight']); + db_query('INSERT INTO {'. fieldgroup_tablename() ."} (gid, pid, type_name, group_name, label, settings, weight) + VALUES (NULL, %d, '%s', '%s', '%s', '%s', %d)", $group['parent'], $type_name, $group_name, $group['label'], serialize($group['settings']), $group['weight']); cache_clear_all('fieldgroup_data', content_cache_tablename()); return SAVED_NEW; } else { - db_query("UPDATE {". fieldgroup_tablename() ."} SET label = '%s', settings = '%s', weight = %d ". - "WHERE type_name = '%s' AND group_name = '%s'", - $group['label'], serialize($group['settings']), $group['weight'], $type_name, $group['group_name']); + db_query("UPDATE {". fieldgroup_tablename() ."} SET pid = %d, label = '%s', settings = '%s', weight = %d WHERE gid = %d", + $group['parent'], $group['label'], serialize($group['settings']), $group['weight'], $group['group_id']); cache_clear_all('fieldgroup_data', content_cache_tablename()); return SAVED_UPDATED; } @@ -563,11 +592,11 @@ if ($default != $form_values['group']) { if ($form_values['group'] && !$default) { - db_query("INSERT INTO {". fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", + db_query('INSERT INTO {'. fieldgroup_fields_tablename() ."} (type_name, group_name, field_name) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $form_values['group'], $form_values['field_name']); } elseif ($form_values['group']) { - db_query("UPDATE {". fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", + db_query('UPDATE {'. fieldgroup_fields_tablename() ."} SET group_name = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['group'], $form_values['type_name'], $form_values['field_name']); } else { @@ -578,7 +607,7 @@ } function fieldgroup_delete($content_type, $group_name) { - db_query("DELETE FROM {". fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); - db_query("DELETE FROM {". fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); + db_query('DELETE FROM {'. fieldgroup_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); + db_query('DELETE FROM {'. fieldgroup_fields_tablename() ."} WHERE type_name = '%s' AND group_name = '%s'", $content_type, $group_name); cache_clear_all('fieldgroup_data', content_cache_tablename()); }