field_test.install 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the field_test module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function field_test_install() {
  10. // hook_entity_info_alter() needs to be executed as last.
  11. db_update('system')
  12. ->fields(array('weight' => 1))
  13. ->condition('name', 'field_test')
  14. ->execute();
  15. }
  16. /**
  17. * Implements hook_schema().
  18. */
  19. function field_test_schema() {
  20. $schema['test_entity'] = array(
  21. 'description' => 'The base table for test_entities.',
  22. 'fields' => array(
  23. 'ftid' => array(
  24. 'description' => 'The primary identifier for a test_entity.',
  25. 'type' => 'serial',
  26. 'unsigned' => TRUE,
  27. 'not null' => TRUE,
  28. ),
  29. 'ftvid' => array(
  30. 'description' => 'The current {test_entity_revision}.ftvid version identifier.',
  31. 'type' => 'int',
  32. 'unsigned' => TRUE,
  33. 'not null' => TRUE,
  34. 'default' => 0,
  35. ),
  36. 'fttype' => array(
  37. 'description' => 'The type of this test_entity.',
  38. 'type' => 'varchar',
  39. 'length' => 32,
  40. 'not null' => TRUE,
  41. 'default' => '',
  42. ),
  43. 'ftlabel' => array(
  44. 'description' => 'The label of this test_entity.',
  45. 'type' => 'varchar',
  46. 'length' => 255,
  47. 'not null' => TRUE,
  48. 'default' => '',
  49. ),
  50. ),
  51. 'unique keys' => array(
  52. 'ftvid' => array('ftvid'),
  53. ),
  54. 'primary key' => array('ftid'),
  55. );
  56. $schema['test_entity_bundle_key'] = array(
  57. 'description' => 'The base table for test entities with a bundle key.',
  58. 'fields' => array(
  59. 'ftid' => array(
  60. 'description' => 'The primary indentifier for a test_entity_bundle_key.',
  61. 'type' => 'int',
  62. 'unsigned' => TRUE,
  63. 'not null' => TRUE,
  64. 'default' => 0,
  65. ),
  66. 'fttype' => array(
  67. 'description' => 'The type of this test_entity.',
  68. 'type' => 'varchar',
  69. 'length' => 32,
  70. 'not null' => FALSE,
  71. 'default' => '',
  72. ),
  73. ),
  74. );
  75. $schema['test_entity_bundle'] = array(
  76. 'description' => 'The base table for test entities with a bundle.',
  77. 'fields' => array(
  78. 'ftid' => array(
  79. 'description' => 'The primary indentifier for a test_entity_bundle.',
  80. 'type' => 'int',
  81. 'unsigned' => TRUE,
  82. 'not null' => TRUE,
  83. 'default' => 0,
  84. ),
  85. ),
  86. );
  87. $schema['test_entity_revision'] = array(
  88. 'description' => 'Stores information about each saved version of a {test_entity}.',
  89. 'fields' => array(
  90. 'ftid' => array(
  91. 'description' => 'The {test_entity} this version belongs to.',
  92. 'type' => 'int',
  93. 'unsigned' => TRUE,
  94. 'not null' => TRUE,
  95. 'default' => 0,
  96. ),
  97. 'ftvid' => array(
  98. 'description' => 'The primary identifier for this version.',
  99. 'type' => 'serial',
  100. 'unsigned' => TRUE,
  101. 'not null' => TRUE,
  102. ),
  103. ),
  104. 'indexes' => array(
  105. 'nid' => array('ftid'),
  106. ),
  107. 'primary key' => array('ftvid'),
  108. );
  109. return $schema;
  110. }
  111. /**
  112. * Implements hook_field_schema().
  113. */
  114. function field_test_field_schema($field) {
  115. if ($field['type'] == 'test_field') {
  116. return array(
  117. 'columns' => array(
  118. 'value' => array(
  119. 'type' => 'int',
  120. 'size' => 'medium',
  121. 'not null' => FALSE,
  122. ),
  123. ),
  124. 'indexes' => array(
  125. 'value' => array('value'),
  126. ),
  127. );
  128. }
  129. else {
  130. return array(
  131. 'columns' => array(
  132. 'shape' => array(
  133. 'type' => 'varchar',
  134. 'length' => 32,
  135. 'not null' => FALSE,
  136. ),
  137. 'color' => array(
  138. 'type' => 'varchar',
  139. 'length' => 32,
  140. 'not null' => FALSE,
  141. ),
  142. ),
  143. );
  144. }
  145. }