text.install

Install, update and uninstall functions for the text module.

File

drupal-7.x/modules/field/modules/text/text.install
View source
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the text module.
  5. */
  6. /**
  7. * Implements hook_field_schema().
  8. */
  9. function text_field_schema($field) {
  10. switch ($field['type']) {
  11. case 'text':
  12. $columns = array(
  13. 'value' => array(
  14. 'type' => 'varchar',
  15. 'length' => $field['settings']['max_length'],
  16. 'not null' => FALSE,
  17. ),
  18. );
  19. break;
  20. case 'text_long':
  21. $columns = array(
  22. 'value' => array(
  23. 'type' => 'text',
  24. 'size' => 'big',
  25. 'not null' => FALSE,
  26. ),
  27. );
  28. break;
  29. case 'text_with_summary':
  30. $columns = array(
  31. 'value' => array(
  32. 'type' => 'text',
  33. 'size' => 'big',
  34. 'not null' => FALSE,
  35. ),
  36. 'summary' => array(
  37. 'type' => 'text',
  38. 'size' => 'big',
  39. 'not null' => FALSE,
  40. ),
  41. );
  42. break;
  43. }
  44. $columns += array(
  45. 'format' => array(
  46. 'type' => 'varchar',
  47. 'length' => 255,
  48. 'not null' => FALSE,
  49. ),
  50. );
  51. return array(
  52. 'columns' => $columns,
  53. 'indexes' => array(
  54. 'format' => array('format'),
  55. ),
  56. 'foreign keys' => array(
  57. 'format' => array(
  58. 'table' => 'filter_format',
  59. 'columns' => array('format' => 'format'),
  60. ),
  61. ),
  62. );
  63. }
  64. /**
  65. * Change text field 'format' columns into varchar.
  66. */
  67. function text_update_7000() {
  68. $spec = array(
  69. 'type' => 'varchar',
  70. 'length' => 255,
  71. 'not null' => FALSE,
  72. );
  73. $fields = _update_7000_field_read_fields(array(
  74. 'module' => 'text',
  75. 'storage_type' => 'field_sql_storage',
  76. ));
  77. foreach ($fields as $field) {
  78. if ($field['deleted']) {
  79. $table = "field_deleted_data_{$field['id']}";
  80. $revision_table = "field_deleted_revision_{$field['id']}";
  81. }
  82. else {
  83. $table = "field_data_{$field['field_name']}";
  84. $revision_table = "field_revision_{$field['field_name']}";
  85. }
  86. $column = $field['field_name'] . '_' . 'format';
  87. db_change_field($table, $column, $column, $spec);
  88. db_change_field($revision_table, $column, $column, $spec);
  89. }
  90. }