#902264: Move hook_field_schema() implementations to .install files.

From: Damien Tournoud <damien@commerceguys.com>


---
 field/field.api.php                 |    3 ++
 field/field.crud.inc                |    3 ++
 field/modules/list/list.install     |   46 +++++++++++++++++++++++++++
 field/modules/list/list.module      |   39 -----------------------
 field/modules/number/number.install |   46 +++++++++++++++++++++++++++
 field/modules/number/number.module  |   39 -----------------------
 field/modules/text/text.install     |   60 +++++++++++++++++++++++++++++++++++
 field/modules/text/text.module      |   53 -------------------------------
 field/tests/field_test.field.inc    |   36 ---------------------
 field/tests/field_test.install      |   36 +++++++++++++++++++++
 file/file.field.inc                 |   32 -------------------
 file/file.install                   |   32 +++++++++++++++++++
 image/image.field.inc               |   31 ------------------
 image/image.install                 |   31 ++++++++++++++++++
 taxonomy/taxonomy.install           |   18 +++++++++++
 taxonomy/taxonomy.module            |   18 -----------
 16 files changed, 275 insertions(+), 248 deletions(-)
 create mode 100644 field/modules/list/list.install
 create mode 100644 field/modules/number/number.install
 create mode 100644 field/modules/text/text.install

diff --git modules/field/field.api.php modules/field/field.api.php
index 40b0d04..0077a45 100644
--- modules/field/field.api.php
+++ 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 modules/field/field.crud.inc modules/field/field.crud.inc
index 3caecce..c27e002 100644
--- modules/field/field.crud.inc
+++ 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 modules/field/modules/list/list.install modules/field/modules/list/list.install
new file mode 100644
index 0000000..38bab8e
--- /dev/null
+++ 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 modules/field/modules/list/list.module modules/field/modules/list/list.module
index d7b069e..769029b 100644
--- modules/field/modules/list/list.module
+++ 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 modules/field/modules/number/number.install modules/field/modules/number/number.install
new file mode 100644
index 0000000..d5e6b1c
--- /dev/null
+++ 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 modules/field/modules/number/number.module modules/field/modules/number/number.module
index 2dc6192..16b88a0 100644
--- modules/field/modules/number/number.module
+++ 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 modules/field/modules/text/text.install modules/field/modules/text/text.install
new file mode 100644
index 0000000..c2c5b2e
--- /dev/null
+++ 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 modules/field/modules/text/text.module modules/field/modules/text/text.module
index c2c06a3..c562611 100644
--- modules/field/modules/text/text.module
+++ 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 modules/field/tests/field_test.field.inc modules/field/tests/field_test.field.inc
index 79212e6..765f6ac 100644
--- modules/field/tests/field_test.field.inc
+++ 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 modules/field/tests/field_test.install modules/field/tests/field_test.install
index d5c8ab8..3181fc8 100644
--- modules/field/tests/field_test.install
+++ 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,
+        ),
+      ),
+    );
+  }
+}
diff --git modules/file/file.field.inc modules/file/file.field.inc
index 2f4297d..0a4f91c 100644
--- modules/file/file.field.inc
+++ modules/file/file.field.inc
@@ -32,38 +32,6 @@ function file_field_info() {
 }
 
 /**
- * Implements hook_field_schema().
- */
-function file_field_schema($field) {
-  return array(
-    'columns' => array(
-      'fid' => array(
-        'description' => 'The {files}.fid being referenced in this field.',
-        'type' => 'int',
-        'not null' => FALSE,
-        'unsigned' => TRUE,
-      ),
-      'display' => array(
-        'description' => 'Flag to control whether this file should be displayed when viewing content.',
-        'type' => 'int',
-        'size' => 'tiny',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 1,
-      ),
-      'description' => array(
-        'description' => 'A description of the file.',
-        'type' => 'text',
-        'not null' => FALSE,
-      ),
-    ),
-    'indexes' => array(
-      'fid' => array('fid'),
-    ),
-  );
-}
-
-/**
  * Implements hook_field_settings_form().
  */
 function file_field_settings_form($field, $instance, $has_data) {
diff --git modules/file/file.install modules/file/file.install
index 7347d19..74ffd4e 100644
--- modules/file/file.install
+++ modules/file/file.install
@@ -7,6 +7,38 @@
  */
 
 /**
+ * Implements hook_field_schema().
+ */
+function file_field_schema($field) {
+  return array(
+    'columns' => array(
+      'fid' => array(
+        'description' => 'The {files}.fid being referenced in this field.',
+        'type' => 'int',
+        'not null' => FALSE,
+        'unsigned' => TRUE,
+      ),
+      'display' => array(
+        'description' => 'Flag to control whether this file should be displayed when viewing content.',
+        'type' => 'int',
+        'size' => 'tiny',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 1,
+      ),
+      'description' => array(
+        'description' => 'A description of the file.',
+        'type' => 'text',
+        'not null' => FALSE,
+      ),
+    ),
+    'indexes' => array(
+      'fid' => array('fid'),
+    ),
+  );
+}
+
+/**
  * Implements hook_requirements().
  *
  * Display information about getting upload progress bars working.
diff --git modules/image/image.field.inc modules/image/image.field.inc
index 1499e56..b3410dd 100644
--- modules/image/image.field.inc
+++ modules/image/image.field.inc
@@ -34,37 +34,6 @@ function image_field_info() {
 }
 
 /**
- * Implements hook_field_schema().
- */
-function image_field_schema($field) {
-  return array(
-    'columns' => array(
-      'fid' => array(
-        'description' => 'The {files}.fid being referenced in this field.',
-        'type' => 'int',
-        'not null' => FALSE,
-        'unsigned' => TRUE,
-      ),
-      'alt' => array(
-        'description' => "Alternative image text, for the image's 'alt' attribute.",
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => FALSE,
-      ),
-      'title' => array(
-        'description' => "Image title text, for the image's 'title' attribute.",
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => FALSE,
-      ),
-    ),
-    'indexes' => array(
-      'fid' => array('fid'),
-    ),
-  );
-}
-
-/**
  * Implements hook_field_settings_form().
  */
 function image_field_settings_form($field, $instance) {
diff --git modules/image/image.install modules/image/image.install
index c45a8da..c8ca4f9 100644
--- modules/image/image.install
+++ modules/image/image.install
@@ -108,6 +108,37 @@ function image_schema() {
 }
 
 /**
+ * Implements hook_field_schema().
+ */
+function image_field_schema($field) {
+  return array(
+    'columns' => array(
+      'fid' => array(
+        'description' => 'The {files}.fid being referenced in this field.',
+        'type' => 'int',
+        'not null' => FALSE,
+        'unsigned' => TRUE,
+      ),
+      'alt' => array(
+        'description' => "Alternative image text, for the image's 'alt' attribute.",
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => FALSE,
+      ),
+      'title' => array(
+        'description' => "Image title text, for the image's 'title' attribute.",
+        'type' => 'varchar',
+        'length' => 128,
+        'not null' => FALSE,
+      ),
+    ),
+    'indexes' => array(
+      'fid' => array('fid'),
+    ),
+  );
+}
+
+/**
  * Install the schema for users upgrading from the contributed module.
  */
 function image_update_7000() {
diff --git modules/taxonomy/taxonomy.install modules/taxonomy/taxonomy.install
index 680403d..e1d6fc4 100644
--- modules/taxonomy/taxonomy.install
+++ modules/taxonomy/taxonomy.install
@@ -222,6 +222,24 @@ function taxonomy_schema() {
 }
 
 /**
+ * Implements hook_field_schema().
+ */
+function taxonomy_field_schema($field) {
+  return array(
+    'columns' => array(
+      'tid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
+    ),
+    'indexes' => array(
+      'tid' => array('tid'),
+    ),
+  );
+}
+
+/**
  * Implements hook_update_dependencies().
  */
 function taxonomy_update_dependencies() {
diff --git modules/taxonomy/taxonomy.module modules/taxonomy/taxonomy.module
index 289e473..f48db7d 100644
--- modules/taxonomy/taxonomy.module
+++ modules/taxonomy/taxonomy.module
@@ -1118,24 +1118,6 @@ function taxonomy_options_list($field) {
 }
 
 /**
- * Implements hook_field_schema().
- */
-function taxonomy_field_schema($field) {
-  return array(
-    'columns' => array(
-      'tid' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => FALSE,
-      ),
-    ),
-    'indexes' => array(
-      'tid' => array('tid'),
-    ),
-  );
-}
-
-/**
  * Implements hook_field_validate().
  *
  * Taxonomy field settings allow for either a single vocabulary ID, multiple
