-
Notifications
You must be signed in to change notification settings - Fork 8
/
liveblog.install
88 lines (82 loc) · 2.41 KB
/
liveblog.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
<?php
/**
* @file
* Install file of the liveblog module.
*/
use Drupal\liveblog\Entity\LiveblogPost;
/**
* Implements hook_install().
*
* Add default highlights.
*/
function liveblog_install() {
$parent = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create([
'name' => 'General',
'vid' => LiveblogPost::LIVEBLOG_POSTS_HIGHLIGHTS_VID,
]);
$parent->save();
$term_names = [
'Breaking news',
'First valid information',
'Official statement',
'Expert analysis',
'New important fact',
'Summary of last hours',
'Unexpected incident',
'Situation under control',
];
foreach ($term_names as $term_name) {
/* @var $term \Drupal\taxonomy\Entity\Term */
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->create([
'name' => $term_name,
'vid' => LiveblogPost::LIVEBLOG_POSTS_HIGHLIGHTS_VID,
]);
$term->parent = [$parent->id()];
$term->save();
}
\Drupal::messenger()->addMessage(t('@count default highlight terms were created.', ['@count' => count($term_names) + 1]));
}
/**
* Implements hook_uninstall().
*/
function liveblog_uninstall() {
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties([
'vid' => LiveblogPost::LIVEBLOG_POSTS_HIGHLIGHTS_VID,
]);
\Drupal::entityTypeManager()->getStorage('taxonomy_term')->delete($terms);
}
/**
* Prefill the channel prefix.
*/
function liveblog_update_8001() {
if (empty(\Drupal::config('liveblog.settings')->get('channel_prefix'))) {
\Drupal::configFactory()->getEditable('liveblog.settings')->set('channel_prefix', 'liveblog')->save();
}
}
/**
* Fix liveblog configuration dependencies.
*/
function liveblog_update_8002() {
$config_to_fix = [
'field.storage.node.field_highlights',
'field.storage.node.field_posts_load_limit',
'field.storage.node.field_posts_number_initial',
'field.storage.node.field_status',
'node.type.liveblog',
'taxonomy.vocabulary.highlights',
];
foreach ($config_to_fix as $name) {
$config = \Drupal::configFactory()->getEditable($name);
$current_dependencies = $config->get('dependencies.enforced.module');
if (!empty($current_dependencies)) {
$current_dependencies[] = 'liveblog';
sort($current_dependencies);
}
else {
$current_dependencies = ['liveblog'];
}
$config
->set('dependencies.enforced.module', $current_dependencies)
->save();
}
}