-
Notifications
You must be signed in to change notification settings - Fork 6
/
localgov_core.install
97 lines (85 loc) · 3.29 KB
/
localgov_core.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
<?php
/**
* @file
* Update hook implementations.
*/
use Drupal\localgov_core\FieldRenameHelper;
/**
* Update Field names for localgov_core provided fields.
*
* Field mapping between existing and new names:
* field_email_address => localgov_email_address
* field_facebook => localgov_facebook
* field_phone => localgov_phone
* field_twitter => localgov_twitter.
*
* This change creates and updates Drupal config entities. Unless configuration
* is *exported* after this update, later calls to 'drush deploy' or similar
* will revert these changes.
*/
function localgov_core_update_8001(&$sandbox) {
// Update field_ types fields provided by localgov_core.
$field_names = ['email_address', 'facebook', 'phone', 'twitter'];
foreach ($field_names as $field_name_unprefixed) {
FieldRenameHelper::renameField('field_' . $field_name_unprefixed, 'localgov_' . $field_name_unprefixed, 'node');
}
return t('Please export your sites configuration! Config entities for localgov_core where updated.');
}
/**
* Update node type conditions from node_type to entity_bundle.
*
* @see pathauto_update_8108()
* This runs the same update for any sites that installed our default pathauto
* patters after the pathauto update was added.
*/
function localgov_core_update_8002() {
// Load all pattern configuration entities.
foreach (\Drupal::configFactory()->listAll('pathauto.pattern.') as $pattern_config_name) {
$pattern_config = \Drupal::configFactory()->getEditable($pattern_config_name);
// Loop patterns and swap the node_type plugin by the entity_bundle:node
// plugin.
if ($pattern_config->get('type') === 'canonical_entities:node') {
$selection_criteria = $pattern_config->get('selection_criteria');
foreach ($selection_criteria as $uuid => $condition) {
if ($condition['id'] === 'node_type') {
$pattern_config->set("selection_criteria.$uuid.id", 'entity_bundle:node');
$pattern_config->save();
break;
}
}
}
}
}
/**
* Add a localgov_card view mode.
*/
function localgov_core_update_8003() {
$view_mode = \Drupal::entityTypeManager()->getStorage('entity_view_mode')->load('node.localgov_card');
if (!$view_mode) {
$view_mode = \Drupal::entityTypeManager()->getStorage('entity_view_mode')->create([
'id' => 'node.localgov_card',
'targetEntityType' => 'node',
'status' => TRUE,
'label' => 'LocalGov Card',
]);
$view_mode->save();
}
}
/**
* Update the files view to change the path and menu type for the 'page_1'.
*/
function localgov_core_update_8004() {
// Load the view configuration.
$config = \Drupal::configFactory()->getEditable('views.view.files');
// Set the configuration values using an array.
$config->set('display.page_1.display_options.path', 'admin/content/media/files');
$config_files_menu_items = $config->get('display.page_1.display_options.menu');
$config_files_menu_items['type'] = 'none';
$config_files_menu_items['expanded'] = 'false';
$config_files_menu_items['parent'] = '';
$config_files_menu_items['context'] = '0';
$config->set('display.page_1.display_options.menu', $config_files_menu_items);
$config->set('display.page_2.display_options.path', 'admin/content/media/files/usage/%');
// Save the configuration.
$config->save();
}