summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/field/field.crud.inc40
-rw-r--r--modules/field/field.form.inc47
-rw-r--r--modules/field/field.install23
-rw-r--r--modules/field/field.module1
-rw-r--r--modules/field/modules/number/number.module8
-rw-r--r--modules/field/modules/text/text.module2
-rw-r--r--modules/field/theme/field.css36
7 files changed, 108 insertions, 49 deletions
diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc
index f994ce35a..3c11abfd4 100644
--- a/modules/field/field.crud.inc
+++ b/modules/field/field.crud.inc
@@ -38,6 +38,8 @@ class FieldException extends Exception {}
* pairs. The object properties are:
*
* @param array $field:
+ * - id (integer, read-only)
+ * The primary identifier of the field.
* - field_name (string)
* The name of the field. Each field name is unique within Field API.
* When a field is attached to an object, the field's data is stored
@@ -75,8 +77,12 @@ class FieldException extends Exception {}
* key/value pairs. The object properties are:
*
* @param array $instance:
+ * - id (integer, read-only)
+ * The primary identifier of this field instance.
+ * - field_id (integer, read-only)
+ * The foreign key of the field attached to the bundle by this instance.
* - field_name (string)
- * The name of field attached by this instance.
+ * The name of the field attached to the bundle by this instance.
* - bundle (string)
* The name of the bundle that the field is attached to.
* - label (string)
@@ -164,7 +170,8 @@ class FieldException extends Exception {}
* bundle; use field_create_instance for that.
*
* @param $field
- * A field structure. The field_name and type properties are required.
+ * A field structure. The field_name and type properties are
+ * required. Read-only properties are assigned automatically.
* @throw
* FieldException
*/
@@ -310,7 +317,7 @@ function field_delete_field($field_name) {
*
* @param $instance
* A field instance structure. The field_name and bundle properties
- * are required.
+ * are required. Read-only properties are assigned automatically.
* @throw
* FieldException
*/
@@ -321,6 +328,9 @@ function field_create_instance($instance) {
throw new FieldException("Attempt to create an instance of a field that doesn't exist.");
}
+ // Set the field id.
+ $instance['field_id'] = $field['id'];
+
// TODO: Check that the specifed bundle exists.
// TODO: Check that the widget type is known and can handle the field type ?
@@ -353,8 +363,9 @@ function field_create_instance($instance) {
* keys and values are:
* field_name: The name of an existing field.
* bundle: The bundle this field belongs to.
- * Any other properties specified in $instance overwrite the
- * existing values for the instance.
+ * Read-only_id properties are assigned automatically. Any other
+ * properties specified in $instance overwrite the existing values for
+ * the instance.
* @throw
* FieldException
* @see field_create_instance()
@@ -373,6 +384,9 @@ function field_update_instance($instance) {
throw new FieldException("Attempt to update a field instance that doesn't exist.");
}
+ $instance['id'] = $prior_instance['id'];
+ $instance['field_id'] = $prior_instance['field_id'];
+
_field_write_instance($instance, TRUE);
// Clear caches.
@@ -442,9 +456,10 @@ function _field_write_instance($instance, $update = FALSE) {
// Create $data to contain everything from $instance that does not
// have its own column, and thus will be stored serialized.
$data = $instance;
- unset($data['field_name'], $data['bundle'], $data['widget']['type'], $data['weight'], $data['deleted']);
+ unset($data['id'], $data['field_id'], $data['field_name'], $data['bundle'], $data['widget']['type'], $data['weight'], $data['deleted']);
$record = array(
+ 'field_id' => $instance['field_id'],
'field_name' => $instance['field_name'],
'bundle' => $instance['bundle'],
'widget_type' => $instance['widget']['type'],
@@ -456,8 +471,13 @@ function _field_write_instance($instance, $update = FALSE) {
);
// We need to tell drupal_update_record() the primary keys to trigger an
// update.
- $primary_keys = $update ? array('field_name', 'bundle') : array();
- drupal_write_record('field_config_instance', $record, $primary_keys);
+ if ($update) {
+ $record['id'] = $instance['id'];
+ $primary_key = array('id');
+ } else {
+ $primary_key = array();
+ }
+ drupal_write_record('field_config_instance', $record, $primary_key);
}
/**
@@ -500,7 +520,7 @@ function field_read_instance($field_name, $bundle, $include_additional = array()
*/
function field_read_instances($params = array(), $include_additional = array()) {
$query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC));
- $query->join('field_config', 'fc', 'fc.field_name = fci.field_name');
+ $query->join('field_config', 'fc', 'fc.id = fci.field_id');
$query->fields('fci');
#$query->fields('fc', array('type'));
@@ -522,6 +542,8 @@ function field_read_instances($params = array(), $include_additional = array())
foreach ($results as $record) {
$instance = unserialize($record['data']);
+ $instance['id'] = $record['id'];
+ $instance['field_id'] = $record['field_id'];
$instance['field_name'] = $record['field_name'];
$instance['bundle'] = $record['bundle'];
$instance['weight'] = $record['weight'];
diff --git a/modules/field/field.form.inc b/modules/field/field.form.inc
index beff3bbb4..8703e852d 100644
--- a/modules/field/field.form.inc
+++ b/modules/field/field.form.inc
@@ -137,12 +137,17 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta
$title = check_plain(t($instance['label']));
$description = field_filter_xss(t($instance['description']));
+ $bundle_name_url_css = str_replace('_', '-', $instance['bundle']);
+ $field_name_url_css = str_replace('_', '-', $field_name);
+
$form_element = array(
'#theme' => 'field_multiple_value_form',
'#multiple' => $field['cardinality'],
'#title' => $title,
'#required' => $instance['required'],
'#description' => $description,
+ '#prefix' => '<div id="' . $field_name_url_css . '-wrapper">',
+ '#suffix' => '</div>',
);
$function = $instance['widget']['module'] . '_field_widget';
@@ -151,6 +156,7 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta
if ($element = $function($form, $form_state, $field, $instance, $items, $delta)) {
$multiple = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
$defaults = array(
+ // For multiple fields, title and description are handled by the wrapping table.
'#title' => $multiple ? '' : $title,
'#description' => $multiple ? '' : $description,
'#required' => $delta == 0 && $instance['required'],
@@ -161,14 +167,14 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta
'#bundle' => $instance['bundle'],
);
- // Add an input field for the delta (drag-n-drop reordering), which will
- // be hidden by tabledrag js behavior.
+ // Input field for the delta (drag-n-drop reordering).
if ($multiple) {
- // We name the element '_weight' to avoid clashing with column names
- // defined by field modules.
+ // We name the element '_weight' to avoid clashing with elements
+ // defined by widget.
$element['_weight'] = array(
'#type' => 'weight',
- '#delta' => $max, // this 'delta' is the 'weight' element's property
+ // Note: this 'delta' is the FAPI 'weight' element's property.
+ '#delta' => $max,
'#default_value' => isset($items[$delta]['_weight']) ? $items[$delta]['_weight'] : $delta,
'#weight' => 100,
);
@@ -193,8 +199,8 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta
// Submit callback for disabled JavaScript.
'#submit' => array('field_add_more_submit'),
'#ahah' => array(
- 'path' => 'field/js_add_more/' . $bundle_name_url_str . '/' . $field_name_url_str,
- 'wrapper' => $field_name_url_str . '-items',
+ 'path' => 'field/js_add_more/' . $bundle_name_url_css . '/' . $field_name_url_css,
+ 'wrapper' => $field_name_url_css . '-wrapper',
'method' => 'replace',
'effect' => 'fade',
),
@@ -202,12 +208,8 @@ function field_multiple_value_form($field, $instance, $items, &$form, &$form_sta
// the relevant field using these entries.
'#field_name' => $field_name,
'#bundle' => $instance['bundle'],
+ '#attributes' => array('class' => 'field-add-more-submit'),
);
-
- // Add wrappers for the fields and 'more' button.
- $form_element['#prefix'] = '<div class="clearfix" id="' . $field_name_url_str . '-add-more-wrapper"><div id="' . $field_name_url_str . '-items">';
- $form_element[$field_name . '_add_more']['#prefix'] = '<div class="field-add-more">';
- $form_element[$field_name . '_add_more']['#suffix'] = '</div></div></div>';
}
}
return $form_element;
@@ -229,8 +231,9 @@ function theme_field_multiple_value_form($element) {
$header = array(
array(
- 'data' => t('!title: !required', array('!title' => $element['#title'], '!required' => $required)),
- 'colspan' => 2
+ 'data' => '<label>' . t('!title: !required', array('!title' => $element['#title'], '!required' => $required)) . "</label>",
+ 'colspan' => 2,
+ 'class' => 'field-label',
),
t('Order'),
);
@@ -240,7 +243,10 @@ function theme_field_multiple_value_form($element) {
// preview or failed validation)
$items = array();
foreach (element_children($element) as $key) {
- if ($key !== $element['#field_name'] . '_add_more') {
+ if ($key === $element['#field_name'] . '_add_more') {
+ $add_more_button = &$element[$key];
+ }
+ else {
$items[] = &$element[$key];
}
}
@@ -261,9 +267,11 @@ function theme_field_multiple_value_form($element) {
);
}
+ $output = '<div class="form-item">';
$output .= theme('table', $header, $rows, array('id' => $table_id, 'class' => 'field-multiple-table'));
$output .= $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '';
- $output .= drupal_render($element[$element['#field_name'] . '_add_more']);
+ $output .= '<div class="clearfix">' . drupal_render($add_more_button) . '</div>';
+ $output .= '</div>';
drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class);
}
@@ -395,10 +403,11 @@ function field_add_more_js($bundle_name, $field_name) {
foreach ($form_path as $key) {
$field_form = $field_form[$key];
}
- // We add a div around the new field to receive the ahah effect.
- $field_form[$delta]['#prefix'] = '<div class="ahah-new-field">' . (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : '');
+ // Add a div around the new field to receive the ahah effect.
+ $field_form[$delta]['#prefix'] = '<div class="ahah-new-content">' . (isset($field_form[$delta]['#prefix']) ? $field_form[$delta]['#prefix'] : '');
$field_form[$delta]['#suffix'] = (isset($field_form[$delta]['#suffix']) ? $field_form[$delta]['#suffix'] : '') . '</div>';
- // TODO : this causes duplication of the wrapping divs
+ // Prevent duplicate wrapper.
+ unset($field_form['#prefix'], $field_form['#suffix']);
// If a newly inserted widget contains AHAH behaviors, they normally won't
// work because AHAH doesn't know about those - it just attaches to the exact
diff --git a/modules/field/field.install b/modules/field/field.install
index 737c1da42..49972a4d0 100644
--- a/modules/field/field.install
+++ b/modules/field/field.install
@@ -15,6 +15,11 @@ function field_schema() {
// Static (meta) tables.
$schema['field_config'] = array(
'fields' => array(
+ 'id' => array(
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => 'The primary identifier for a field',
+ ),
'field_name' => array(
'type' => 'varchar',
'length' => 32,
@@ -66,7 +71,8 @@ function field_schema() {
'default' => 0,
),
),
- 'primary key' => array('field_name'),
+ 'primary key' => array('id'),
+ 'unique keys' => array('field_name' => array('field_name')),
'indexes' => array(
// used by field_read_fields
'active_deleted' => array('active', 'deleted'),
@@ -78,6 +84,16 @@ function field_schema() {
);
$schema['field_config_instance'] = array(
'fields' => array(
+ 'id' => array(
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ 'description' => 'The primary identifier for a field instance',
+ ),
+ 'field_id' => array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'description' => 'The identifier of the field attached by this instance',
+ ),
'field_name' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
'bundle' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
'widget_type' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
@@ -106,7 +122,10 @@ function field_schema() {
'default' => 0,
),
),
- 'primary key' => array('field_name', 'bundle'),
+ 'primary key' => array('id'),
+ 'unique keys' => array(
+ 'field_name_bundle' => array('field_name', 'bundle'),
+ ),
'indexes' => array(
// used by field_read_instances
'widget_active_deleted' => array('widget_active', 'deleted'),
diff --git a/modules/field/field.module b/modules/field/field.module
index a6f111a45..2f93cea22 100644
--- a/modules/field/field.module
+++ b/modules/field/field.module
@@ -107,6 +107,7 @@ function field_help($path, $arg) {
function field_init() {
module_load_include('inc', 'field', 'field.crud');
module_load_include('inc', 'field', 'field.autoload');
+ drupal_add_css(drupal_get_path('module', 'field') . '/theme/field.css');
}
/**
diff --git a/modules/field/modules/number/number.module b/modules/field/modules/number/number.module
index cd213d065..28202758a 100644
--- a/modules/field/modules/number/number.module
+++ b/modules/field/modules/number/number.module
@@ -51,7 +51,7 @@ function number_field_info() {
function number_field_columns($field) {
switch ($field['type']) {
case 'number_integer' :
- $colums = array(
+ $columns = array(
'value' => array(
'type' => 'int',
'not null' => FALSE
@@ -60,7 +60,7 @@ function number_field_columns($field) {
break;
case 'number_float' :
- $colums = array(
+ $columns = array(
'value' => array(
'type' => 'float',
'not null' => FALSE
@@ -69,7 +69,7 @@ function number_field_columns($field) {
break;
case 'number_decimal' :
- $colums = array(
+ $columns = array(
'value' => array(
'type' => 'numeric',
'precision' => $field['settings']['precision'],
@@ -79,7 +79,7 @@ function number_field_columns($field) {
);
break;
}
- return $colums;
+ return $columns;
}
/**
diff --git a/modules/field/modules/text/text.module b/modules/field/modules/text/text.module
index 69fb41913..46b85229b 100644
--- a/modules/field/modules/text/text.module
+++ b/modules/field/modules/text/text.module
@@ -39,6 +39,7 @@ function text_field_info() {
'description' => t('This field stores varchar text in the database.'),
'settings' => array('max_length' => 255),
'instance_settings' => array('text_processing' => 0),
+ 'widget_settings' => array('size' => 60),
'default_widget' => 'text_textfield',
'default_formatter' => 'text_default',
),
@@ -46,6 +47,7 @@ function text_field_info() {
'label' => t('Long text'),
'description' => t('This field stores long text in the database.'),
'instance_settings' => array('text_processing' => 0),
+ 'widget_settings' => array('rows' => 5),
'default_widget' => 'text_textarea',
'default_formatter' => 'text_default',
),
diff --git a/modules/field/theme/field.css b/modules/field/theme/field.css
index aa9a4921c..167da2296 100644
--- a/modules/field/theme/field.css
+++ b/modules/field/theme/field.css
@@ -1,32 +1,38 @@
/* $Id$ */
-/* Node display */
+/* Field display */
.field .field-label,
.field .field-label-inline,
.field .field-label-inline-first {
- font-weight:bold;
+ font-weight: bold;
}
.field .field-label-inline,
.field .field-label-inline-first {
- display:inline;
+ display: inline;
}
.field .field-label-inline {
- visibility:hidden;
+ visibility: hidden;
}
-.node-form .field-multiple-table td.field-multiple-drag {
- width:30px;
- padding-right:0;
+form .field-multiple-table {
+ margin: 0;
}
-.node-form .field-multiple-table td.field-multiple-drag a.tabledrag-handle{
- padding-right:.5em;
+form .field-multiple-table th.field-label {
+ padding-left: 0;
}
-
-.node-form .field-add-more .form-submit{
- margin:0;
+form .field-multiple-table td.field-multiple-drag {
+ width: 30px;
+ padding-right: 0;
+}
+form .field-multiple-table td.field-multiple-drag a.tabledrag-handle{
+ padding-right: .5em;
}
-.node-form .number {
- display:inline;
- width:auto;
+form .field-add-more-submit {
+ margin: .5em 0 0;
}
+
+.form-item .number {
+ display: inline;
+ width: auto;
+} \ No newline at end of file