Skip to content

Commit de0da88

Browse files
authored
Issue #7: Convert conditions into deployable config files.
By @laryn, @yorkshire-pudding, @herbdool, @argiepiano, and @jenlampton.
1 parent 17386cf commit de0da88

File tree

6 files changed

+197
-141
lines changed

6 files changed

+197
-141
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ at **admin/structure/dependencies**.
3434

3535
More details may be found (or contributed to) in the [Wiki](https://github.com/backdrop-contrib/conditional_fields/issues)
3636

37-
3837
Issues
3938
------
4039

@@ -43,16 +42,17 @@ Bugs and Feature requests should be reported in the [Issue Queue](https://github
4342
Current Maintainers
4443
-------------------
4544

46-
- [Laryn Kragt Bakker](https://github.com/laryn), [CEDC.org](https://CEDC.org)
45+
- [Laryn Kragt Bakker](https://github.com/laryn)
4746
- Co-maintainers wanted
4847

4948
Credits
5049
-------
5150

52-
- Ported to Backdrop by [Laryn Kragt Bakker](https://github.com/laryn), [CEDC.org](https://CEDC.org)
51+
- Ported to Backdrop by [Laryn Kragt Bakker](https://github.com/laryn)
52+
- Ongoing Backdrop development is supported by [Aten Design Group](https://aten.io)
53+
- Initial port to Backdrop sponsored by [CEDC.org](https://CEDC.org)
5354
- Originally written by and maintained for Drupal by [Gregorio Magini](https://www.drupal.org/u/peterpoe)
5455

55-
5656
License
5757
-------
5858

conditional_fields.install

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,6 @@
44
* Install, update and uninstall functions for the Conditional Fields module.
55
*/
66

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-
447
/**
458
* Implements hook_update_last_removed().
469
*/
@@ -52,7 +15,6 @@ function conditional_fields_update_last_removed() {
5215
* Adjust schema and data for new field instance identifier format.
5316
*/
5417
function conditional_fields_update_1000() {
55-
$config = config('conditional_fields.settings');
5618
if (db_table_exists('conditional_fields')) {
5719
db_change_field('conditional_fields', 'dependee', 'dependee', array(
5820
'description' => 'The id of the dependee field instance.',
@@ -92,5 +54,44 @@ function conditional_fields_update_1000() {
9254
->execute();
9355
}
9456
}
57+
}
9558

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+
}
9697
}

0 commit comments

Comments
 (0)