comparison modules/field/tests/field_test.install @ 0:ff03f76ab3fe

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