-
Notifications
You must be signed in to change notification settings - Fork 27
/
wxt.install
141 lines (128 loc) · 3.36 KB
/
wxt.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @file
* Install and uninstall functions for the WxT installation profile.
*/
use Drupal\menu_link_content\Entity\MenuLinkContent;
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function wxt_install() {
_wxt_setup_themes();
_wxt_setup_branding();
_wxt_setup_menus();
_wxt_setup_lang_prefixes();
_wxt_setup_404();
}
/**
* Set up the default branding.
*/
function _wxt_setup_branding() {
// Set the path to the logo, favicon and README file based on install
// directory.
$wxt_path = \Drupal::service('extension.list.profile')->getPath('wxt');
\Drupal::configFactory()
->getEditable('system.theme.global')
->set('logo', [
'path' => $wxt_path . '/wxt.svg',
'url' => '',
'use_default' => FALSE,
])
->set('favicon', [
'mimetype' => 'image/vnd.microsoft.icon',
'path' => $wxt_path . '/favicon.ico',
'url' => '',
'use_default' => FALSE,
])
->save(TRUE);
}
/**
* Setup languages prefixes.
*/
function _wxt_setup_lang_prefixes() {
$config = \Drupal::configFactory()->getEditable('language.negotiation');
$prefixes = $config->get('url.prefixes');
foreach (\Drupal::languageManager()->getLanguages() as $language) {
if (empty($prefixes[$language->getId()])) {
// For all defined languages set prefix to langcode.
$prefixes[$language->getId()] = $language->getId();
}
}
$config->set('url.prefixes', $prefixes)->save();
}
/**
* Set up the default menu override(s).
*/
function _wxt_setup_menus() {
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $user_account */
$parent_link = MenuLinkContent::create([
'menu_name' => 'account',
'link' => 'route:<nolink>',
'title' => 'User Account',
'expanded' => TRUE,
]);
$parent_link->save();
$menu_links = [
'user.page',
'user.logout',
];
foreach ($menu_links as $menu_link) {
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$link = $menu_link_manager->getDefinition($menu_link);
$link['parent'] = $parent_link->getPluginId();
$menu_link_manager->updateDefinition($menu_link, $link);
$cache = \Drupal::cache('menu');
$cache->deleteAll();
}
}
/**
* Setup the themes.
*/
function _wxt_setup_themes() {
// Set the default and admin theme.
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'wxt_bootstrap')
->set('admin', 'claro')
->save(TRUE);
// Enable the admin theme.
\Drupal::configFactory()
->getEditable('node.settings')
->set('use_admin_theme', TRUE)
->save(TRUE);
}
/**
* Setup default 403/404.
*/
function _wxt_setup_404() {
// Set default "403".
\Drupal::configFactory()
->getEditable('system.site')
->set('page.403', '/system/404')
->save(TRUE);
// Set default "404".
\Drupal::configFactory()
->getEditable('system.site')
->set('page.404', '/system/404')
->save(TRUE);
}
/**
* Implements hook_update_N().
*
* Opt in to newer gcweb look for existing installs.
*/
function wxt_update_8201() {
$config = \Drupal::configFactory()->getEditable('wxt_library.settings');
$config->set('wxt.theme', 'theme-gcweb-legacy');
$config->save();
}
/**
* Installs the layout library module.
*/
function wxt_update_8202() {
\Drupal::service('module_installer')->install(['layout_library']);
}