summaryrefslogtreecommitdiff
path: root/modules/field
diff options
context:
space:
mode:
Diffstat (limited to 'modules/field')
-rw-r--r--modules/field/field.api.php3
-rw-r--r--modules/field/field.crud.inc3
-rw-r--r--modules/field/modules/list/list.install46
-rw-r--r--modules/field/modules/list/list.module39
-rw-r--r--modules/field/modules/number/number.install46
-rw-r--r--modules/field/modules/number/number.module39
-rw-r--r--modules/field/modules/text/text.install60
-rw-r--r--modules/field/modules/text/text.module53
-rw-r--r--modules/field/tests/field_test.field.inc36
-rw-r--r--modules/field/tests/field_test.install36
10 files changed, 194 insertions, 167 deletions
diff --git a/modules/field/field.api.php b/modules/field/field.api.php
index a3d8bdbf4..9b2d3bb4f 100644
--- a/modules/field/field.api.php
+++ b/modules/field/field.api.php
@@ -211,6 +211,9 @@ function hook_field_info_alter(&$info) {
/**
* Define the Field API schema for a field structure.
*
+ * This hook MUST be defined in .install for it to be detected during
+ * installation and upgrade.
+ *
* @param $field
* A field structure.
*
diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc
index e7fa00146..96e44bf0e 100644
--- a/modules/field/field.crud.inc
+++ b/modules/field/field.crud.inc
@@ -317,6 +317,7 @@ function field_create_field($field) {
$field['storage']['module'] = $storage_type['module'];
$field['storage']['active'] = 1;
// Collect storage information.
+ module_load_install($field['module']);
$schema = (array) module_invoke($field['module'], 'field_schema', $field);
$schema += array('columns' => array(), 'indexes' => array());
// 'columns' are hardcoded in the field type.
@@ -426,6 +427,7 @@ function field_update_field($field) {
// Collect the new storage information, since what is in
// $prior_field may no longer be right.
+ module_load_install($field['module']);
$schema = (array) module_invoke($field['module'], 'field_schema', $field);
$schema += array('columns' => array(), 'indexes' => array());
// 'columns' are hardcoded in the field type.
@@ -552,6 +554,7 @@ function field_read_fields($params = array(), $include_additional = array()) {
module_invoke_all('field_read_field', $field);
// Populate storage information.
+ module_load_install($field['module']);
$schema = (array) module_invoke($field['module'], 'field_schema', $field);
$schema += array('columns' => array(), 'indexes' => array());
$field['columns'] = $schema['columns'];
diff --git a/modules/field/modules/list/list.install b/modules/field/modules/list/list.install
new file mode 100644
index 000000000..38bab8e7d
--- /dev/null
+++ b/modules/field/modules/list/list.install
@@ -0,0 +1,46 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Install, update and uninstall functions for the list module.
+ */
+
+/**
+ * Implements hook_field_schema().
+ */
+function list_field_schema($field) {
+ switch ($field['type']) {
+ case 'list_text':
+ $columns = array(
+ 'value' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => FALSE,
+ ),
+ );
+ break;
+ case 'list_number':
+ $columns = array(
+ 'value' => array(
+ 'type' => 'float',
+ 'not null' => FALSE,
+ ),
+ );
+ break;
+ default:
+ $columns = array(
+ 'value' => array(
+ 'type' => 'int',
+ 'not null' => FALSE,
+ ),
+ );
+ break;
+ }
+ return array(
+ 'columns' => $columns,
+ 'indexes' => array(
+ 'value' => array('value'),
+ ),
+ );
+} \ No newline at end of file
diff --git a/modules/field/modules/list/list.module b/modules/field/modules/list/list.module
index 8aa3489a2..bbf6bd9ff 100644
--- a/modules/field/modules/list/list.module
+++ b/modules/field/modules/list/list.module
@@ -56,45 +56,6 @@ function list_field_info() {
}
/**
- * Implements hook_field_schema().
- */
-function list_field_schema($field) {
- switch ($field['type']) {
- case 'list_text':
- $columns = array(
- 'value' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- ),
- );
- break;
- case 'list_number':
- $columns = array(
- 'value' => array(
- 'type' => 'float',
- 'not null' => FALSE,
- ),
- );
- break;
- default:
- $columns = array(
- 'value' => array(
- 'type' => 'int',
- 'not null' => FALSE,
- ),
- );
- break;
- }
- return array(
- 'columns' => $columns,
- 'indexes' => array(
- 'value' => array('value'),
- ),
- );
-}
-
-/**
* Implements hook_field_settings_form().
*
* @todo: If $has_data, add a form validate function to verify that the
diff --git a/modules/field/modules/number/number.install b/modules/field/modules/number/number.install
new file mode 100644
index 000000000..d5e6b1cf2
--- /dev/null
+++ b/modules/field/modules/number/number.install
@@ -0,0 +1,46 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Install, update and uninstall functions for the number module.
+ */
+
+/**
+ * Implements hook_field_schema().
+ */
+function number_field_schema($field) {
+ switch ($field['type']) {
+ case 'number_integer' :
+ $columns = array(
+ 'value' => array(
+ 'type' => 'int',
+ 'not null' => FALSE
+ ),
+ );
+ break;
+
+ case 'number_float' :
+ $columns = array(
+ 'value' => array(
+ 'type' => 'float',
+ 'not null' => FALSE
+ ),
+ );
+ break;
+
+ case 'number_decimal' :
+ $columns = array(
+ 'value' => array(
+ 'type' => 'numeric',
+ 'precision' => $field['settings']['precision'],
+ 'scale' => $field['settings']['scale'],
+ 'not null' => FALSE
+ ),
+ );
+ break;
+ }
+ return array(
+ 'columns' => $columns,
+ );
+}
diff --git a/modules/field/modules/number/number.module b/modules/field/modules/number/number.module
index d9386eda7..cfc1b6d62 100644
--- a/modules/field/modules/number/number.module
+++ b/modules/field/modules/number/number.module
@@ -51,45 +51,6 @@ function number_field_info() {
}
/**
- * Implements hook_field_schema().
- */
-function number_field_schema($field) {
- switch ($field['type']) {
- case 'number_integer' :
- $columns = array(
- 'value' => array(
- 'type' => 'int',
- 'not null' => FALSE
- ),
- );
- break;
-
- case 'number_float' :
- $columns = array(
- 'value' => array(
- 'type' => 'float',
- 'not null' => FALSE
- ),
- );
- break;
-
- case 'number_decimal' :
- $columns = array(
- 'value' => array(
- 'type' => 'numeric',
- 'precision' => $field['settings']['precision'],
- 'scale' => $field['settings']['scale'],
- 'not null' => FALSE
- ),
- );
- break;
- }
- return array(
- 'columns' => $columns,
- );
-}
-
-/**
* Implements hook_field_settings_form().
*/
function number_field_settings_form($field, $instance, $has_data) {
diff --git a/modules/field/modules/text/text.install b/modules/field/modules/text/text.install
new file mode 100644
index 000000000..c2c5b2ec7
--- /dev/null
+++ b/modules/field/modules/text/text.install
@@ -0,0 +1,60 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Install, update and uninstall functions for the text module.
+ */
+
+/**
+ * Implements hook_field_schema().
+ */
+function text_field_schema($field) {
+ switch ($field['type']) {
+ case 'text':
+ $columns = array(
+ 'value' => array(
+ 'type' => 'varchar',
+ 'length' => $field['settings']['max_length'],
+ 'not null' => FALSE,
+ ),
+ );
+ break;
+ case 'text_long':
+ $columns = array(
+ 'value' => array(
+ 'type' => 'text',
+ 'size' => 'big',
+ 'not null' => FALSE,
+ ),
+ );
+ break;
+ case 'text_with_summary':
+ $columns = array(
+ 'value' => array(
+ 'type' => 'text',
+ 'size' => 'big',
+ 'not null' => FALSE,
+ ),
+ 'summary' => array(
+ 'type' => 'text',
+ 'size' => 'big',
+ 'not null' => FALSE,
+ ),
+ );
+ break;
+ }
+ $columns += array(
+ 'format' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => FALSE,
+ ),
+ );
+ return array(
+ 'columns' => $columns,
+ 'indexes' => array(
+ 'format' => array('format'),
+ ),
+ );
+}
diff --git a/modules/field/modules/text/text.module b/modules/field/modules/text/text.module
index 600081c1b..45ace5ee2 100644
--- a/modules/field/modules/text/text.module
+++ b/modules/field/modules/text/text.module
@@ -58,59 +58,6 @@ function text_field_info() {
}
/**
- * Implements hook_field_schema().
- */
-function text_field_schema($field) {
- switch ($field['type']) {
- case 'text':
- $columns = array(
- 'value' => array(
- 'type' => 'varchar',
- 'length' => $field['settings']['max_length'],
- 'not null' => FALSE,
- ),
- );
- break;
- case 'text_long':
- $columns = array(
- 'value' => array(
- 'type' => 'text',
- 'size' => 'big',
- 'not null' => FALSE,
- ),
- );
- break;
- case 'text_with_summary':
- $columns = array(
- 'value' => array(
- 'type' => 'text',
- 'size' => 'big',
- 'not null' => FALSE,
- ),
- 'summary' => array(
- 'type' => 'text',
- 'size' => 'big',
- 'not null' => FALSE,
- ),
- );
- break;
- }
- $columns += array(
- 'format' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => FALSE,
- ),
- );
- return array(
- 'columns' => $columns,
- 'indexes' => array(
- 'format' => array('format'),
- ),
- );
-}
-
-/**
* Implements hook_field_settings_form().
*/
function text_field_settings_form($field, $instance, $has_data) {
diff --git a/modules/field/tests/field_test.field.inc b/modules/field/tests/field_test.field.inc
index 6bb8dd87b..603eadd6a 100644
--- a/modules/field/tests/field_test.field.inc
+++ b/modules/field/tests/field_test.field.inc
@@ -47,42 +47,6 @@ function field_test_field_info() {
}
/**
- * Implements hook_field_schema().
- */
-function field_test_field_schema($field) {
- if ($field['type'] == 'test_field') {
- return array(
- 'columns' => array(
- 'value' => array(
- 'type' => 'int',
- 'size' => 'medium',
- 'not null' => FALSE,
- ),
- ),
- 'indexes' => array(
- 'value' => array('value'),
- ),
- );
- }
- else {
- return array(
- 'columns' => array(
- 'shape' => array(
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => FALSE,
- ),
- 'color' => array(
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => FALSE,
- ),
- ),
- );
- }
-}
-
-/**
* Implements hook_field_update_forbid().
*/
function field_test_field_update_forbid($field, $prior_field, $has_data) {
diff --git a/modules/field/tests/field_test.install b/modules/field/tests/field_test.install
index d16d79ee8..d4937b620 100644
--- a/modules/field/tests/field_test.install
+++ b/modules/field/tests/field_test.install
@@ -106,3 +106,39 @@ function field_test_schema() {
return $schema;
}
+
+/**
+ * Implements hook_field_schema().
+ */
+function field_test_field_schema($field) {
+ if ($field['type'] == 'test_field') {
+ return array(
+ 'columns' => array(
+ 'value' => array(
+ 'type' => 'int',
+ 'size' => 'medium',
+ 'not null' => FALSE,
+ ),
+ ),
+ 'indexes' => array(
+ 'value' => array('value'),
+ ),
+ );
+ }
+ else {
+ return array(
+ 'columns' => array(
+ 'shape' => array(
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => FALSE,
+ ),
+ 'color' => array(
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => FALSE,
+ ),
+ ),
+ );
+ }
+}