-
Notifications
You must be signed in to change notification settings - Fork 7
/
druxxy.profile
98 lines (87 loc) · 3.07 KB
/
druxxy.profile
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
<?php
/**
* @file
* Enables modules and site configuration for a multilingual installation.
*
* Copied from https://www.drupal.org/project/multilingual_demo project.
*/
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Symfony\Component\Yaml\Parser;
/**
* Implements hook_install_tasks().
*
* @see https://www.drupal.org/project/drupal/issues/2982052
*/
function druxxy_install_tasks(&$install_state) {
return [
'druxxy_install_setup' => [
'display_name' => t('Install setup'),
'type' => 'normal',
],
'druxxy_install_import_language_config' => [],
];
}
/**
* Performs actions to set up the site for this profile.
*/
function druxxy_install_setup() {
// Assign user 1 the "sysadmin" role.
$user = User::load(1);
$user->roles[] = 'sysadmin';
$user->save();
// Allow authenticated users to use shortcuts.
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
}
/**
* Implements hook_install_tasks_alter().
*/
function druxxy_install_tasks_alter(&$tasks, $install_state) {
// Moves the language config import task to the end of the install tasks so
// that it is run after the final import of languages.
$task = $tasks['druxxy_install_import_language_config'];
unset($tasks['druxxy_install_import_language_config']);
$tasks = array_merge($tasks, ['druxxy_install_import_language_config' => $task]);
}
/**
* Imports language configuration overrides.
*/
function druxxy_install_import_language_config() {
$language_manager = \Drupal::languageManager();
$yaml_parser = new Parser();
// The language code of the default locale.
$site_default_langcode = $language_manager->getDefaultLanguage()->getId();
// The directory where the language config files reside.
$language_config_directory = __DIR__ . '/config/install/language';
if (!is_dir($language_config_directory)) {
return;
}
// Sub-directory names (language codes).
// The language code of the default language is excluded. If the user
// chooses to install in Hungarian, French, or Spanish, the language config is
// imported by core and the user has the chance to override it during the
// installation process.
$langcodes = array_diff(scandir($language_config_directory), [
'..',
'.',
$site_default_langcode,
]);
foreach ($langcodes as $langcode) {
// All .yml files in the language's config subdirectory.
$config_files = glob("$language_config_directory/$langcode/*.yml");
foreach ($config_files as $file_name) {
// Information from the .yml file as an array.
$yaml = $yaml_parser->parse(file_get_contents($file_name));
// Uses the base name of the .yml file to get the config name.
$config_name = basename($file_name, '.yml');
// The language configuration object.
$config = $language_manager->getLanguageConfigOverride($langcode, $config_name);
foreach ($yaml as $config_key => $config_value) {
// Updates the configuration object.
$config->set($config_key, $config_value);
}
// Saves the configuration.
$config->save();
}
}
}