summaryrefslogtreecommitdiff
path: root/modules/field/tests/field_test.install
blob: 59575611033c5fec5f1453b8b3b58c598597588b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php

/**
 * @file
 * Install, update and uninstall functions for the field_test module.
 */

/**
 * Implements hook_install().
 */
function field_test_install() {
  // hook_entity_info_alter() needs to be executed as last.
  db_update('system')
    ->fields(array('weight' => 1))
    ->condition('name', 'field_test')
    ->execute();
}

/**
 * Implements hook_schema().
 */
function field_test_schema() {
  $schema['test_entity'] = array(
    'description' => 'The base table for test_entities.',
    'fields' => array(
      'ftid' => array(
        'description' => 'The primary identifier for a test_entity.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'ftvid' => array(
        'description' => 'The current {test_entity_revision}.ftvid version identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'fttype' => array(
        'description' => 'The type of this test_entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'ftlabel' => array(
        'description' => 'The label of this test_entity.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'unique keys' => array(
      'ftvid' => array('ftvid'),
    ),
    'primary key' => array('ftid'),
  );
  $schema['test_entity_bundle_key'] = array(
    'description' => 'The base table for test entities with a bundle key.',
    'fields' => array(
      'ftid' => array(
        'description' => 'The primary indentifier for a test_entity_bundle_key.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'fttype' => array(
        'description' => 'The type of this test_entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => FALSE,
        'default' => '',
      ),
    ),
  );
  $schema['test_entity_bundle'] = array(
    'description' => 'The base table for test entities with a bundle.',
    'fields' => array(
      'ftid' => array(
        'description' => 'The primary indentifier for a test_entity_bundle.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
  );
  $schema['test_entity_revision'] = array(
    'description' => 'Stores information about each saved version of a {test_entity}.',
    'fields' => array(
      'ftid' => array(
        'description' => 'The {test_entity} this version belongs to.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'ftvid' => array(
        'description' => 'The primary identifier for this version.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'nid' => array('ftid'),
    ),
    'primary key' => array('ftvid'),
  );

  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,
        ),
      ),
    );
  }
}