-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoe_multilingual.install
102 lines (85 loc) · 3.19 KB
/
oe_multilingual.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
<?php
/**
* @file
* Install, update and uninstall functions for the oe_multilingual module.
*/
declare(strict_types=1);
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\oe_multilingual\Plugin\LanguageNegotiation\LanguageNegotiationAdmin;
/**
* Implements hook_install().
*/
function oe_multilingual_install($is_syncing) {
if ($is_syncing) {
// If config is syncing, we do nothing here.
return;
}
// Set EU category for the English language.
\Drupal::entityTypeManager()
->getStorage('configurable_language')
->load('en')
->setThirdPartySetting('oe_multilingual', 'category', 'eu')
->save();
// Set up the weight of the English language.
\Drupal::configFactory()
->getEditable('language.entity.en')
->set('weight', 7)
->save();
// Disable remote translations downloading from Drupal localisation service.
// Also make sure that English language is translatable.
\Drupal::configFactory()
->getEditable('locale.settings')
->set('translation.import_enabled', FALSE)
->save();
// Make sure that English language prefix is set to "en".
\Drupal::configFactory()
->getEditable('language.negotiation')
->set('url.prefixes.en', 'en')
->save();
// Make sure that Portuguese language prefix is set to "pt".
\Drupal::configFactory()
->getEditable('language.negotiation')
->set('url.prefixes.pt-pt', 'pt')
->save();
/** @var \Drupal\oe_multilingual\LanguageNegotiationSetterInterface $setter */
$setter = \Drupal::service('oe_multilingual.language_negotiation_setter');
// Set default language negotiation methods.
$setter->enableNegotiationMethods([
LanguageInterface::TYPE_INTERFACE,
LanguageInterface::TYPE_CONTENT,
]);
// For interface negotiation make sure administrative pages are in English.
$setter->setInterfaceSettings([
LanguageNegotiationAdmin::METHOD_ID => -20,
LanguageNegotiationUrl::METHOD_ID => -19,
LanguageNegotiationSelected::METHOD_ID => 20,
]);
// For content negotiation make sure that content respects URL language.
$setter->setContentSettings([
LanguageNegotiationUrl::METHOD_ID => -19,
LanguageNegotiationSelected::METHOD_ID => 20,
]);
\Drupal::messenger()->addMessage('Please be aware that oe_multilingual makes changes to the following configurations: Language, Locale, Administration language negotiation.');
}
/**
* Implements hook_uninstall().
*/
function oe_multilingual_uninstall() {
// Unset the LanguageNegotiationAdmin plugin from the interface negotiation.
// This is needed because the plugin is defined by this module.
$names = [
'negotiation.' . LanguageInterface::TYPE_INTERFACE . '.enabled',
'negotiation.' . LanguageInterface::TYPE_INTERFACE . '.method_weights',
];
$config = \Drupal::configFactory()->getEditable('language.types');
foreach ($names as $name) {
$settings = $config->get($name);
if (isset($settings[LanguageNegotiationAdmin::METHOD_ID])) {
unset($settings[LanguageNegotiationAdmin::METHOD_ID]);
}
$config->set($name, $settings);
}
$config->save();
}