forked from esmero/strawberryfield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrawberryfield.install
57 lines (52 loc) · 1.9 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
<?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();
}
}
}