-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_field.install
More file actions
65 lines (57 loc) · 1.42 KB
/
change_field.install
File metadata and controls
65 lines (57 loc) · 1.42 KB
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
<?php
/**
* An install hook that changes a field from text to long text type.
* It changes the field data and field revision storage.
*/
/**
* Alters field_my_text and reverts related features.
*/
function my_module_update_7160() {
// Changes field_my_text from text to long text.
db_query("UPDATE {field_config} SET type = 'text_long' WHERE field_name = 'field_my_text'");
// For field data.
db_drop_primary_key('field_data_field_my_text');
db_change_field('field_data_field_my_text', 'field_my_text_value', 'field_my_text_value',
[
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
],
[
'primary key' => [
'entity_type',
'entity_id',
'deleted',
'delta',
'language',
],
]
);
// For field revision.
db_drop_primary_key('field_revision_field_my_text');
db_change_field('field_revision_field_my_text', 'field_my_text_value', 'field_my_text_value',
[
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
],
[
'primary key' => [
'entity_type',
'entity_id',
'deleted',
'delta',
'language',
],
]
);
field_cache_clear(TRUE);
// Reverts features for field change and new text format.
$modules = [
'my_features_module',
'my_other_features_module',
];
foreach ($modules as $module) {
features_revert_module($module);
}
}