This repository was archived by the owner on Mar 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfarm_surveystack.post_update.php
More file actions
89 lines (79 loc) · 2.93 KB
/
Copy pathfarm_surveystack.post_update.php
File metadata and controls
89 lines (79 loc) · 2.93 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* @file
* Post update functions for SurveyStack module.
*/
/**
* Add hidden surveystack_id field to assets and logs.
*/
function farm_surveystack_post_update_surveystack_id(&$sandbox) {
$field_id = 'surveystack_id';
$field_definition = \Drupal::service('farm_field.factory')->baseFieldDefinition([
'type' => 'string',
'label' => t('Surveystack ID'),
'hidden' => TRUE,
]);
foreach (['asset', 'log'] as $entity_type) {
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition($field_id, $entity_type, 'farm_surveystack', $field_definition);
}
}
/**
* Install Common profile module.
*/
function farm_surveystack_post_update_enable_profile_common(&$sandbox = NULL) {
if (!\Drupal::service('module_handler')->moduleExists('farm_profile_common')) {
\Drupal::service('module_installer')->install(['farm_profile_common']);
}
}
/**
* Add surveystack_id field to profiles.
*/
function farm_surveystack_post_update_surveystack_id_profile(&$sandbox = NULL) {
$field_definition = \Drupal::service('farm_field.factory')->baseFieldDefinition([
'type' => 'string',
'label' => t('Surveystack ID'),
'hidden' => TRUE,
]);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('surveystack_id', 'profile', 'farm_surveystack', $field_definition);
}
/**
* Install SurveyStack Conventions module.
*/
function farm_surveystack_post_update_enable_surveystack_convention(&$sandbox = NULL) {
// First, delete all custom flags. This is safe to do because the flag field
// stores the flag ID string, not a reference to the config entity itself.
// So once farm_surveystack_convention is installed, these will be recreated.
$flags = [
'greenhouse',
'hydroponic',
'non_gmo',
'organic_not_cert',
'regenerative',
'transitionalregen',
];
foreach ($flags as $flag) {
\Drupal::configFactory()->getEditable('farm_flag.flag.' . $flag)->delete();
}
// Install farm_surveystack_convention.
if (!\Drupal::service('module_handler')->moduleExists('farm_surveystack_convention')) {
\Drupal::service('module_installer')->install(['farm_surveystack_convention']);
}
}
/**
* Update SurveyStack OAuth client for Simple OAuth v6.
*/
function farm_surveystack_post_update_simple_oauth_v6(&$sandbox = NULL) {
// Enable the simple_oauth_password_grant module.
if (!\Drupal::service('module_handler')->moduleExists('simple_oauth_password_grant')) {
\Drupal::service('module_installer')->install(['simple_oauth_password_grant']);
}
// Update existing surveystack_aggregator consumer.
$consumers = \Drupal::entityTypeManager()->getStorage('consumer')
->loadByProperties(['client_id' => 'surveystack_aggregator']);
if (!empty($consumers)) {
/** @var \Drupal\consumers\Entity\ConsumerInterface $consumer */
$consumer = reset($consumers);
$consumer->set('grant_types', ['authorization_code', 'refresh_token', 'password']);
$consumer->save();
}
}