-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhetzner_api.install
More file actions
44 lines (39 loc) · 1.22 KB
/
hetzner_api.install
File metadata and controls
44 lines (39 loc) · 1.22 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
<?php
use Drupal\node\Entity\NodeType;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
/**
* Implements hook_install().
*/
function hetzner_api_install() {
if (!NodeType::load('hetzner_server')) {
$type = NodeType::create([
'type' => 'hetzner_server',
'name' => 'Hetzner Server',
'description' => 'Synkroniseret server fra Hetzner Cloud',
]);
$type->save();
}
$fields = [
'field_server_id' => ['label' => 'Server ID', 'type' => 'string'],
'field_status' => ['label' => 'Status', 'type' => 'string'],
'field_ipv4' => ['label' => 'IPv4', 'type' => 'string'],
'field_location' => ['label' => 'Location', 'type' => 'string'],
'field_specs' => ['label' => 'Specs', 'type' => 'string'],
];
foreach ($fields as $field_name => $info) {
if (!FieldStorageConfig::loadByName('node', $field_name)) {
FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'type' => $info['type'],
])->save();
FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'hetzner_server',
'label' => $info['label'],
])->save();
}
}
}