forked from esmero/ami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ami.install
118 lines (105 loc) · 3.45 KB
/
ami.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
108
109
110
111
112
113
114
115
<?php
/**
* @file
* Contains install and update functions for AMI.
*/
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;
use Drupal\Component\Utility\Environment;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Database\Database;
use Drupal\Core\Config\Entity\ConfigEntityType;
/**
* Implements hook_install().
*/
function ami_install() {
}
/**
* Update 8901 - Create AMI Set entity.
*/
function ami_update_8901() {
// Code provided by @giancarloby to allow D9 compat.
$schema = Database::getConnection()->schema();
if (!$schema->tableExists('ami_setentity')) {
\Drupal::entityTypeManager()->clearCachedDefinitions();
\Drupal::entityDefinitionUpdateManager()
->installEntityType(\Drupal::entityTypeManager()->getDefinition('ami_set_entity'));
}
else {
return 'AMI Set entity already exists';
}
}
/**
* Update 8902 - Add ZIP file Field for AMI Set entity.
*/
function ami_update_8902() {
$validators = [
'file_validate_extensions' => ['zip'],
'file_validate_size' => [Environment::getUploadMaxSize()],
];
$storage_definition = BaseFieldDefinition::create('file')
->setLabel(new TranslatableMarkup('Attached ZIP file'))
->setDescription(new TranslatableMarkup('A Zip file containing accompanying Files for the Source Data'))
->setSetting('file_extensions', 'zip')
->setSetting('upload_validators', $validators)
->setSetting('uri_scheme', 'private')
->setSetting('file_directory', '/ami/zip')
->setRequired(FALSE)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'file',
'weight' => -3,
])
->setDisplayOptions('form', [
'type' => 'file',
'description' => [
'theme' => 'file_upload_help',
'description' => new TranslatableMarkup('Source Files for this Set')
],
'settings' => [
'upload_validators' => $validators,
],
'weight' => -3,
])
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('zip_file', 'ami_set_entity', 'ami', $storage_definition);
}
/**
* Update 8903 - Install Importer Adapter Config Entity.
*/
function ami_update_8903() {
\Drupal::entityDefinitionUpdateManager()->installEntityType(new ConfigEntityType([
'id' => 'importeradapter',
'label' => new TranslatableMarkup('AMI Importer Adapter'),
'config_prefix' => 'importeradapter',
'admin_permission' => 'administer site configuration',
'entity_keys' => [
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
],
'config_export' => [
"id",
"label",
"plugin",
"update_existing",
"target_entity_types",
"active",
"plugin_configuration"
],
]));
}
/**
* Update 8903 - Make Private default upload location for ami Set ZIP files.
*/
function ami_update_8904() {
$field_storage_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('zip_file', 'ami_set_entity');
$field_storage_definition->setSetting('uri_scheme', 'private');
$field_storage_definition->setSetting('file_directory', '/ami/zip');
\Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition($field_storage_definition);
}