-
Notifications
You must be signed in to change notification settings - Fork 1
/
localgov_elections.install
81 lines (68 loc) · 2.42 KB
/
localgov_elections.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
<?php
/**
* @file
* Install, update and uninstall functions for the LocalGov Elections Module.
*/
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Entity\EntityStorageException;
/**
* Implements hook_install().
*/
function localgov_elections_install($is_syncing) {
$module_path = \Drupal::getContainer()
->get('module_handler')
->getModule('localgov_elections')
->getPath();
$overrides = $module_path . '/config/override';
$files = new FileStorage($overrides);
foreach ($files->listAll() as $id) {
$config_data = $files->read($id);
$config = \Drupal::configFactory()->getEditable($id);
$config->setData($config_data)->save();
}
}
/**
* Implements hook_uninstall().
*/
function localgov_elections_uninstall($is_syncing) {
$storage_handler = \Drupal::entityTypeManager()
->getStorage('node');
$nodes = $storage_handler->loadByProperties(['type' => 'localgov_election']);
try {
$storage_handler->delete($nodes);
}
catch (EntityStorageException $e) {
}
$nodes = $storage_handler->loadByProperties(['type' => 'localgov_area_vote']);
try {
$storage_handler->delete($nodes);
}
catch (EntityStorageException $e) {
}
}
/**
* Update results view for already installed module.
*/
function localgov_elections_update_10001(&$sandbox) {
$config_obj = \Drupal::configFactory()->getEditable('views.view.localgov_election_results');
$config_obj->set('display.block_3.display_options.fields.localgov_election_votes.alter.alter_text', TRUE);
$config_obj->set('display.block_3.display_options.fields.localgov_election_votes.alter.text', '{% if localgov_election_votes_final == "1" %} {{ localgov_election_votes }} {% endif %}');
$config_obj->save();
Drupal::logger('localgov_elections')->notice("Updated results view");
}
/**
* Make election results area more robust for when candidates have no surname.
*/
function localgov_elections_update_10002() {
$module_path = \Drupal::getContainer()
->get('module_handler')
->getModule('localgov_elections')
->getPath();
$install_dir = new FileStorage($module_path . '/config/install/');
$data = $install_dir->read('views.view.localgov_election_area_results');
$config_obj = \Drupal::configFactory()->getEditable('views.view.localgov_election_area_results');
$config_obj->setData($data);
$config_obj->save(TRUE);
Drupal::logger('localgov_elections')->notice("Updated election area results view");
drupal_flush_all_caches();
}