-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloco_translate.install
73 lines (64 loc) · 3.17 KB
/
loco_translate.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
<?php
/**
* @file
* Contains loco_translate.install.
*/
use Drupal\Core\Url;
/**
* Implements hook_install().
*/
function loco_translate_install() {
$messenger = \Drupal::messenger();
$messenger->addMessage(t("Loco Translate is installed and ready for action."));
// Asserts loco/loco is installed.
if (!class_exists('Loco\Http\ApiClient')) {
$messenger->addError(t('Loco Translate requires the <a href=":sdk-url" target="_blank">external Loco SDK</a>. The recommended way of solving this dependency is using <a href=":composer-url" target="_blank">Composer</a> running the following from the command line: <br /><code>composer require loco/loco:^2.0</code>', [
':sdk-url' => 'https://github.com/loco/loco-php-sdk',
':composer-url' => 'https://getcomposer.org',
]));
}
}
/**
* Implements hook_requirements().
*/
function loco_translate_requirements($phase) {
$requirements = [];
// Asserts loco/loco is installed.
if (!class_exists('Loco\Http\ApiClient')) {
$requirements['loco_translate_loco_sdk'] = [
'title' => t('Loco libraries'),
'value' => t('Missing libraries'),
'severity' => REQUIREMENT_ERROR,
'description' => t('Loco Translate requires the <a href=":sdk-url" target="_blank">external Loco SDK</a>. The recommended way of solving this dependency is using <a href=":composer-url" target="_blank">Composer</a> running the following from the command line: <br /><code>composer require loco/loco:^2.0</code>', [
':sdk-url' => 'https://github.com/loco/loco-php-sdk',
':composer-url' => 'https://getcomposer.org',
]),
];
}
$config = \Drupal::config('loco_translate.settings');
if ($phase == 'runtime') {
if (empty($config->get('api.readonly_key'))) {
$requirements['loco_translate_readonly_key'] = [
'title' => t('Loco Export API key'),
'value' => t('Missing'),
'severity' => REQUIREMENT_ERROR,
'description' => t('Loco Translate requires your Export API key. Keep this key secret by adding it in your <code>settings.php</code> or fill the <a href=":settings-url">Settings form</a>. You may find more informations about API keys on <a href=":loco-url" target="_blank">Loco support</a> pages', [
':loco-url' => 'https://localise.biz/help/developers/api-keys',
':settings-url' => Url::fromRoute('loco_translate.settings', [], ['fragment' => 'edit-api'])->toString(),
]),
];
}
if (empty($config->get('api.fullaccess_key'))) {
$requirements['loco_translate_fullaccess_key'] = [
'title' => t('Loco Full Access API key'),
'value' => t('Missing'),
'severity' => REQUIREMENT_ERROR,
'description' => t('Loco Translate requires your Full Access API key. Keep this key secret by adding it in your <code>settings.php</code> or fill the <a href="">Settings form</a>. You may find more informations about API keys on <a href=":loco-url" target="_blank">Loco support</a> pages', [
':loco-url' => 'https://localise.biz/help/developers/api-keys',
':settings-url' => Url::fromRoute('loco_translate.settings', [], ['fragment' => 'edit-api'])->toString(),
]),
];
}
}
return $requirements;
}