-
Notifications
You must be signed in to change notification settings - Fork 5
/
strawberryfield.install
107 lines (99 loc) · 3.66 KB
/
strawberryfield.install
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
<?php
/**
* @file
* Contains install and update functions for strawberryfield.
*/
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
/**
* Implements hook_install().
*/
function strawberryfield_install() {
$vid = "strawberryfield_voc_id";
$name = "Strawberryfield Metadata Keys";
$vocabularies = Vocabulary::loadMultiple();
if (!isset($vocabularies[$vid])) {
// Create a vocabulary to hold strawberryfield json keys.
$vocabulary = Vocabulary::create([
'name' => $name,
'description' => 'Holds Strawberry Field provided JSON Keys. Populated automatically on node save.',
'vid' => $vid,
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'weight' => 0,
]);
$vocabulary->save();
// Add a translatable field to the vocabulary.
$fieldstorage = FieldStorageConfig::create(array(
'field_name' => 'field_jsonpath',
'entity_type' => 'taxonomy_term',
'type' => 'text',
));
$fieldstorage->save();
$field = FieldConfig::create(['field_storage' => $fieldstorage, 'bundle' => $vid]);
$field->save();
}
}
/**
* Adds entity_type default to entity reference strawberry keynameprovider.
*/
function strawberryfield_update_9101() {
$config_factory = \Drupal::configFactory();
// Find strawberry_keynameprovider configs that are using the entity jmespath
// provider and have no entity type set yet.
foreach ($config_factory->listAll('strawberryfield.strawberry_keynameprovider.') as $keynameprovider_name) {
$keynameprovider = $config_factory->getEditable($keynameprovider_name);
if ($keynameprovider->get('pluginid') == 'entityjmespath' && $keynameprovider->get('pluginconfig.entity_type') == NULL) {
$keynameprovider->set('pluginconfig.entity_type', 'node')->save();
}
}
}
/**
* Update node type conditions from node_type to entity_bundle.
*
* This hook is only needed if installing from 0 with old 9.2.x configs
* @see https://www.drupal.org/node/2983299
*
* @note (Adapted from pathauto.install)
*/
function strawberryfield_update_9102() {
$config_factory = \Drupal::configFactory();
// Check and update pathauto
$selection_criteria = $config_factory->get('pathauto.pattern.digital_object_uuid')->get('selection_criteria');
if($selection_criteria) {
$pattern_config = \Drupal::configFactory()->getEditable('pathauto.pattern.digital_object_uuid');
foreach ($selection_criteria as $uuid => $condition) {
if ($condition['id'] === 'node_type') {
$pattern_config->set("selection_criteria.$uuid.id", 'entity_bundle:node');
$pattern_config->save();
break;
}
}
}
// Check and update blocks
$config_factory = \Drupal::configFactory();
foreach ($config_factory->listAll('block.block.') as $block_config_name) {
$block = $config_factory->getEditable($block_config_name);
if ($block->get('visibility.node_type')) {
$configuration = $block->get('visibility.node_type');
$configuration['id'] = 'entity_bundle:node';
$block->set('visibility.entity_bundle:node', $configuration);
$block->clear('visibility.node_type');
$block->save(TRUE);
}
}
}
/**
* Update multipart_upload_threshold
*
*/
function strawberryfield_update_9103() {
$storage_settings = \Drupal::configFactory()->getEditable('strawberryfield.storage_settings');
$multipart_upload_threshold = $storage_settings->get('multipart_upload_threshold');
if (!$multipart_upload_threshold) {
$storage_settings->set('multipart_upload_threshold', 5368709120);
$storage_settings->save(TRUE);
}
}