Commit 38181f13 authored by JonBob's avatar JonBob

http://drupal.org/node/50059

Per-field help text. Currently only visible in text widget; to be added to
all widgets.
parent 3ced5b13
...@@ -31,6 +31,7 @@ function content_install() { ...@@ -31,6 +31,7 @@ function content_install() {
label varchar(255) NOT NULL default '', label varchar(255) NOT NULL default '',
widget_type varchar(32) NOT NULL default '', widget_type varchar(32) NOT NULL default '',
widget_settings mediumtext NOT NULL, widget_settings mediumtext NOT NULL,
description mediumtext NOT NULL,
PRIMARY KEY (field_name,type_name) PRIMARY KEY (field_name,type_name)
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
break; break;
...@@ -59,10 +60,30 @@ function content_install() { ...@@ -59,10 +60,30 @@ function content_install() {
label varchar(255) NOT NULL default '', label varchar(255) NOT NULL default '',
widget_type varchar(32) NOT NULL default '', widget_type varchar(32) NOT NULL default '',
widget_settings text NOT NULL, widget_settings text NOT NULL,
description text NOT NULL,
PRIMARY KEY (field_name,type_name) PRIMARY KEY (field_name,type_name)
)"); )");
break; break;
} }
} }
/**
* Add storage for per-field help text.
*/
function content_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_add_column($ret, 'node_field_instance', 'description', 'text', array('not null' => TRUE, 'default' => ''));
break;
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {node_field_instance} ADD COLUMN description mediumtext NOT NULL");
break;
}
return $ret;
}
...@@ -493,7 +493,7 @@ function _content_types($reset = FALSE) { ...@@ -493,7 +493,7 @@ function _content_types($reset = FALSE) {
$type_result = db_query('SELECT * FROM {node_type} nt ORDER BY nt.type_name ASC'); $type_result = db_query('SELECT * FROM {node_type} nt ORDER BY nt.type_name ASC');
while ($type = db_fetch_object($type_result)) { while ($type = db_fetch_object($type_result)) {
$type->fields = array(); $type->fields = array();
$field_result = db_query("SELECT nfi.field_name, nfi.weight, nfi.label, nfi.widget_type, nfi.widget_settings, nf.type, nf.global_settings, nf.required, nf.multiple FROM {node_field_instance} nfi LEFT JOIN {node_field} nf ON nfi.field_name = nf.field_name 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, nf.type, nf.global_settings, nf.required, nf.multiple FROM {node_field_instance} nfi LEFT JOIN {node_field} nf ON nfi.field_name = nf.field_name WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type->type_name);
while ($field = db_fetch_array($field_result)) { while ($field = db_fetch_array($field_result)) {
$field_settings = $field['global_settings'] ? unserialize($field['global_settings']) : array(); $field_settings = $field['global_settings'] ? unserialize($field['global_settings']) : array();
$widget_settings = $field['widget_settings'] ? unserialize($field['widget_settings']) : array(); $widget_settings = $field['widget_settings'] ? unserialize($field['widget_settings']) : array();
...@@ -507,6 +507,8 @@ function _content_types($reset = FALSE) { ...@@ -507,6 +507,8 @@ function _content_types($reset = FALSE) {
unset($field['weight']); unset($field['weight']);
$field['widget']['label'] = $field['label']; $field['widget']['label'] = $field['label'];
unset($field['label']); unset($field['label']);
$field['widget']['description'] = $field['description'];
unset($field['description']);
$type->fields[$field['field_name']] = $field; $type->fields[$field['field_name']] = $field;
} }
......
...@@ -502,6 +502,14 @@ function _content_admin_field($type_name, $field_name) { ...@@ -502,6 +502,14 @@ function _content_admin_field($type_name, $field_name) {
if ($additions = module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget'])) { if ($additions = module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget'])) {
$form['widget'] = array_merge($form['widget'], $additions); $form['widget'] = array_merge($form['widget'], $additions);
} }
$form['widget']['description'] = array(
'#type' => 'textarea',
'#title' => t('Help text'),
'#default_value' => $field['widget']['description'],
'#rows' => 5,
'#description' => t('Instructions to present to the user below this field on the editing form.'),
'#required' => FALSE,
);
$form['field'] = array( $form['field'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
...@@ -583,7 +591,7 @@ function _content_admin_field_submit($form_id, $form_values) { ...@@ -583,7 +591,7 @@ function _content_admin_field_submit($form_id, $form_values) {
$prev_field = $field; $prev_field = $field;
$prev_columns = module_invoke($field_type['module'], 'field_settings', 'database columns', $field); $prev_columns = module_invoke($field_type['module'], 'field_settings', 'database columns', $field);
db_query("UPDATE {node_field_instance} SET weight = %d, label = '%s', widget_type = '%s', widget_settings = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['weight'], $form_values['label'], $form_values['widget_type'], serialize($widget_settings), $form_values['type_name'], $form_values['field_name']); db_query("UPDATE {node_field_instance} SET weight = %d, label = '%s', widget_type = '%s', widget_settings = '%s', description = '%s' WHERE type_name = '%s' AND field_name = '%s'", $form_values['weight'], $form_values['label'], $form_values['widget_type'], serialize($widget_settings), $form_values['description'], $form_values['type_name'], $form_values['field_name']);
db_query("UPDATE {node_field} SET required = %d, multiple = %d, global_settings = '%s' WHERE field_name = '%s'", $form_values['required'], $form_values['multiple'], serialize($field_settings), $form_values['field_name']); db_query("UPDATE {node_field} SET required = %d, multiple = %d, global_settings = '%s' WHERE field_name = '%s'", $form_values['required'], $form_values['multiple'], serialize($field_settings), $form_values['field_name']);
......
...@@ -171,6 +171,7 @@ function text_widget($op, &$node, $field) { ...@@ -171,6 +171,7 @@ function text_widget($op, &$node, $field) {
'#title' => t($field['widget']['label']), '#title' => t($field['widget']['label']),
'#default_value' => $node_field['value'], '#default_value' => $node_field['value'],
'#required' => $field['required'], '#required' => $field['required'],
'#description' => $field['widget']['description'],
); );
} }
else { else {
...@@ -180,6 +181,7 @@ function text_widget($op, &$node, $field) { ...@@ -180,6 +181,7 @@ function text_widget($op, &$node, $field) {
'#default_value' => $node_field['value'], '#default_value' => $node_field['value'],
'#required' => $field['required'], '#required' => $field['required'],
'#rows' => $field['widget']['rows'], '#rows' => $field['widget']['rows'],
'#description' => $field['widget']['description'],
); );
} }
if ($field['text_processing']) { if ($field['text_processing']) {
......
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