4
4
* Install, update and uninstall functions for the Conditional Fields module.
5
5
*/
6
6
7
- /**
8
- * Implements hook_schema().
9
- */
10
- function conditional_fields_schema() {
11
- $schema['conditional_fields'] = array(
12
- 'description' => 'Stores dependencies between fields.',
13
- 'fields' => array(
14
- 'id' => array(
15
- 'type' => 'serial',
16
- 'not null' => TRUE,
17
- 'description' => 'The primary identifier for a dependency.',
18
- ),
19
- 'dependee' => array(
20
- 'type' => 'varchar',
21
- 'not null' => TRUE,
22
- 'length' => 128,
23
- 'description' => 'The id of the dependee field instance.',
24
- ),
25
- 'dependent' => array(
26
- 'type' => 'varchar',
27
- 'not null' => TRUE,
28
- 'length' => 128,
29
- 'description' => 'The id of the dependent field instance.',
30
- ),
31
- 'options' => array(
32
- 'type' => 'blob',
33
- 'size' => 'big',
34
- 'not null' => TRUE,
35
- 'serialize' => TRUE,
36
- 'description' => 'Serialized data containing the options for the dependency.',
37
- ),
38
- ),
39
- 'primary key' => array('id'),
40
- );
41
- return $schema;
42
- }
43
-
44
7
/**
45
8
* Implements hook_update_last_removed().
46
9
*/
@@ -52,7 +15,6 @@ function conditional_fields_update_last_removed() {
52
15
* Adjust schema and data for new field instance identifier format.
53
16
*/
54
17
function conditional_fields_update_1000() {
55
- $config = config('conditional_fields.settings');
56
18
if (db_table_exists('conditional_fields')) {
57
19
db_change_field('conditional_fields', 'dependee', 'dependee', array(
58
20
'description' => 'The id of the dependee field instance.',
@@ -92,5 +54,44 @@ function conditional_fields_update_1000() {
92
54
->execute();
93
55
}
94
56
}
57
+ }
95
58
59
+ /**
60
+ * Convert configuration to use deployable CMI instead of storing in database.
61
+ */
62
+ function conditional_fields_update_1100() {
63
+ // Remove unneeded config file, if it exists.
64
+ $config = config('conditional_fields.settings');
65
+ if (!$config->isNew()) {
66
+ $config->delete();
67
+ }
68
+
69
+ // Convert the database-stored configuration to CMI.
70
+ if (db_table_exists('conditional_fields')) {
71
+ $select = db_select('conditional_fields', 'cf');
72
+ $select->fields('cf', array('options', 'dependee', 'dependent'));
73
+ $select->orderBy('cf.dependent');
74
+ $result = $select->execute();
75
+ foreach ($result as $conditional) {
76
+ $config = config('conditional_field.' . $conditional->dependent . '.settings');
77
+ if ($config->isNew()) {
78
+ $parts = explode('.', $conditional->dependent);
79
+ $config->set('label', t('Conditionals for Field @field - Entity @entity; Bundle @bundle', array(
80
+ '@field' => $parts[2],
81
+ '@entity' => $parts[0],
82
+ '@bundle' => $parts[1],
83
+ )));
84
+ $config->set('type', $conditional->dependent);
85
+ }
86
+ // Update the ID with the new format.
87
+ $formatted_dependee = array(
88
+ 'dependee' => explode('.', $conditional->dependee)[2],
89
+ 'options' => unserialize($conditional->options),
90
+ );
91
+ $uuid = new Uuid();
92
+ $config->set($uuid->generate(), $formatted_dependee);
93
+ $config->save();
94
+ }
95
+ db_drop_table('conditional_fields');
96
+ }
96
97
}
0 commit comments