Commit 57b50b1c authored by JonBob's avatar JonBob

New interface for adding fields and assigning widgets simultaneously.

parent d4f794e9
......@@ -2,8 +2,8 @@ Content Construction Kit
------------------------
For information about the CCK, see http://drupal.org/cck-status
To install, place the entire cck folder into your modules directory.
Go to administer -> modules and enable the content module and one or
To install, place the entire cck folder into your modules directory.
Go to administer -> modules and enable the content module and one or
more field type modules:
- text.module
......@@ -13,7 +13,7 @@ more field type modules:
- nodereference.module
Now go to administer -> content -> content types. Create a new
content type and edit it to add some fields. Then test by creating
content type and edit it to add some fields. Then test by creating
a new node of your new type using the create content menu link.
jvandyk [at] iastate.edu
......
......@@ -30,7 +30,7 @@ function content_install() {
PRIMARY KEY (field_name,type_name)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {node_type} (
type_name varchar(32) NOT NULL default '',
......
......@@ -518,6 +518,7 @@ function _content_admin_field_add($type_name) {
$type = $types[$type_name];
$field_types = _content_field_types();
$fields = _content_fields();
$widget_types = _content_widget_types();
$output = '';
$options = array();
......@@ -561,14 +562,20 @@ function _content_admin_field_add($type_name) {
);
$options = array();
foreach ($field_types as $field_name => $field_type) {
$options[$field_name] = $field_type['label'];
foreach ($widget_types as $widget_name => $widget_type) {
if (in_array($field_name, $widget_type['field types'])) {
$options[$field_name .'-'. $widget_name] = $widget_type['label'];
}
}
}
$form['new']['type'] = array(
$form['new']['field_widget_type'] = array(
'#type' => 'radios',
'#title' => t('Field type'),
'#required' => TRUE,
'#options' => $options,
'#theme' => 'content_admin_field_add_new_field_widget_type',
);
$form['new']['submit'] = array(
'#type' => 'submit',
'#value' => t('Create field'),
......@@ -582,6 +589,28 @@ function _content_admin_field_add($type_name) {
return $output;
}
function theme_content_admin_field_add_new_field_widget_type($form) {
$types = _content_types();
$type = $types[$type_name];
$field_types = _content_field_types();
$fields = _content_fields();
$widget_types = _content_widget_types();
$output = '';
$output .= '<dl>';
foreach ($field_types as $field_name => $field_type) {
$output .= '<dt>'. $field_type['label'] .'</dt>';
foreach ($widget_types as $widget_name => $widget_type) {
if (in_array($field_name, $widget_type['field types'])) {
$output .= '<dd>'. form_render($form[$field_name .'-'. $widget_name]) .'</dd>';
}
}
}
$output .= '</dl>';
return $output;
}
/**
* Add an existing field to a content type.
*/
......@@ -605,10 +634,9 @@ function _content_admin_field_add_existing_submit($form_id, $form_values) {
* Create a new field for a content type.
*/
function _content_admin_field_add_new_submit($form_id, $form_values) {
// Find a valid, computer-friendly type name.
// Find a valid, computer-friendly field name.
$field_types = _content_field_types();
$field_type = $field_types[$form_values['type']];
$fields = _content_fields();
$field_name = trim($form_values['label']);
$field_name = drupal_strtolower($field_name);
......@@ -616,17 +644,18 @@ function _content_admin_field_add_new_submit($form_id, $form_values) {
$field_name = preg_replace('/[^a-z0-9_]/', '', $field_name);
$field_name = 'field_'. $field_name;
$field_name = substr($field_name, 0, 31);
if (isset($types['$field_name'])) {
if (isset($fields[$field_name])) {
$counter = 0;
do {
$new_name = substr($field_name, 0, 29) .'_'. $counter++;
} while (isset($types['$new_name']));
} while (isset($fields[$new_name]));
$field_name = $new_name;
}
db_query("INSERT INTO {node_field} (field_name, type) VALUES ('%s', '%s')", $field_name, $form_values['type']);
$field_widget_type = explode('-', $form_values['field_widget_type']);
db_query("INSERT INTO {node_field} (field_name, type) VALUES ('%s', '%s')", $field_name, $field_widget_type[0]);
db_query("INSERT INTO {node_field_instance} (type_name, field_name, label) VALUES ('%s', '%s', '%s')", $form_values['type_name'], $field_name, $form_values['label']);
db_query("INSERT INTO {node_field_instance} (type_name, field_name, label, widget_type) VALUES ('%s', '%s', '%s', '%s')", $form_values['type_name'], $field_name, $form_values['label'], $field_widget_type[1]);
drupal_set_message(t('Created field %label.', array('%label' => theme('placeholder', $form_values['label']))));
content_clear_type_cache();
......
......@@ -12,7 +12,7 @@ function date_install() {
PRIMARY KEY (vid,field_name,delta)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {node_field_date_data} (
vid integer unsigned NOT NULL default '0',
......
......@@ -12,7 +12,7 @@
function date_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Defines a date/time field type.');
return t('Defines a date/time field type. <em>Note: Requires content.module.</em>');
}
}
......
......@@ -12,7 +12,7 @@ function nodereference_install() {
PRIMARY KEY (vid,field_name,delta)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {node_field_nodereference_data} (
vid integer unsigned NOT NULL default '0',
......
......@@ -12,7 +12,7 @@
function nodereference_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Defines a field type for referencing one node from another.');
return t('Defines a field type for referencing one node from another. <em>Note: Requires content.module.</em>');
}
}
......@@ -287,16 +287,16 @@ function nodereference_views_tables() {
foreach ($fields as $field) {
if ($field['type'] == 'nodereference') {
$tables['node_field_nodereference_data_'. $field['field_name']] = array(
'name' => 'node_field_nodereference_data',
'name' => 'node_field_nodereference_data',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'vid',
),
),
'right' => array(
'field' => 'vid',
'extra' => array('field_name' => $field['field_name']),
),
),
),
'fields' => array(
'field_nid' => array(
......@@ -315,16 +315,16 @@ function nodereference_views_tables() {
),
);
$tables['node_field_nodereference_data_reverse_'. $field['field_name']] = array(
'name' => 'node_field_nodereference_data',
'name' => 'node_field_nodereference_data',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid',
),
),
'right' => array(
'field' => 'field_nid',
'extra' => array('field_name' => $field['field_name']),
),
),
),
'fields' => array(
'vid' => array(
......
......@@ -20,7 +20,7 @@ function number_install() {
PRIMARY KEY (vid,field_name,delta)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {node_field_float_data} (
vid integer unsigned NOT NULL default '0',
......
......@@ -12,7 +12,7 @@
function number_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Defines numeric field types.');
return t('Defines numeric field types. <em>Note: Requires content.module.</em>');
}
}
......@@ -302,16 +302,16 @@ function number_views_tables() {
foreach ($fields as $field) {
if ($field['type'] == 'number_integer') {
$tables['node_field_int_data_'. $field['field_name']] = array(
'name' => 'node_field_int_data',
'name' => 'node_field_int_data',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'vid',
),
),
'right' => array(
'field' => 'vid',
'extra' => array('field_name' => $field['field_name']),
),
),
),
'fields' => array(
'field_int' => array(
......@@ -339,16 +339,16 @@ function number_views_tables() {
}
if ($field['type'] == 'number_decimal') {
$tables['node_field_float_data_'. $field['field_name']] = array(
'name' => 'node_field_float_data',
'name' => 'node_field_float_data',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'vid',
),
),
'right' => array(
'field' => 'vid',
'extra' => array('field_name' => $field['field_name']),
),
),
),
'fields' => array(
'field_int' => array(
......
......@@ -22,7 +22,7 @@ function text_install() {
PRIMARY KEY (vid,field_name,delta)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {node_field_longtext_data} (
vid integer unsigned NOT NULL default '0',
......
......@@ -12,7 +12,7 @@
function text_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Defines simple text field types.');
return t('Defines simple text field types. <em>Note: Requires content.module.</em>');
}
}
......@@ -280,7 +280,7 @@ function text_widget($op, &$node, $field) {
case 'validate':
return;
case 'submit':
return;
}
......@@ -311,16 +311,16 @@ function text_views_tables() {
foreach ($fields as $field) {
if ($field['type'] == 'text_shorttext') {
$tables['node_field_shorttext_data_'. $field['field_name']] = array(
'name' => 'node_field_shorttext_data',
'name' => 'node_field_shorttext_data',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'vid',
),
),
'right' => array(
'field' => 'vid',
'extra' => array('field_name' => $field['field_name']),
),
),
),
'fields' => array(
'field_shorttext' => array(
......@@ -335,11 +335,11 @@ function text_views_tables() {
'field_shorttext' => array(
'name' => 'Short Text: '. $field['field_name'],
'operator' => array(
'=' => 'is',
'contains' => 'contains',
'begins' => 'begins with',
'ends' => 'ends wth',
'LIKE' => 'matches pattern',
'=' => 'is',
'contains' => 'contains',
'begins' => 'begins with',
'ends' => 'ends wth',
'LIKE' => 'matches pattern',
),
'operator-handler' => '_text_filter_operator',
),
......
......@@ -12,7 +12,7 @@ function userreference_install() {
PRIMARY KEY (vid,field_name,delta)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {node_field_userreference_data} (
vid integer unsigned NOT NULL default '0',
......
......@@ -12,7 +12,7 @@
function userreference_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Defines a field type for referencing a user from a node.');
return t('Defines a field type for referencing a user from a node. <em>Note: Requires content.module.</em>');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment