-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_multiling.module
211 lines (196 loc) · 7.53 KB
/
custom_multiling.module
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
function custom_multiling_enable() {
$admin_role = user_role_load_by_name('administrator');
$modules = array('locale','translation','i18n','i18n_block','i18n_variable', 'i18n_menu','i18n_node', 'i18n_string', 'i18n_path', 'l10n_client','l10n_update','title','entity_translation', 'i18n_panels');
foreach ($modules as $module) {
//check one more time if module is installed & enabled before perm set
if (!module_exists($module)) {
module_enable(array($module), TRUE);
}
//setup permissions
switch($module) {
case 'locale':
user_role_grant_permissions($admin_role->rid, array('administer languages','translate interface'),'locale');
break;
case 'translation':
user_role_grant_permissions($admin_role->rid, array('translate content'),'translation');
break;
case 'l10n_client':
user_role_grant_permissions($admin_role->rid, array('use on-page translation','submit translations to localization server'),'l10n_client');
break;
case 'l10n_update':
user_role_grant_permissions($admin_role->rid, array('translate interface'),'l10n_update');
break;
case 'i18n': //makes sure admin site config is enabled for admins, which it should be
user_role_grant_permissions($admin_role->rid, array('administer site configuration'),'system');
break;
case 'i18n_node':
user_role_grant_permissions($admin_role->rid, array('administer content translations'),'i18n_node');
break;
case 'entity_translation':
user_role_grant_permissions($admin_role->rid, array('administer entity translation','toggle field translatability','translate any entity'),'entity_translation');
break;
case 'i18n_string':
user_role_grant_permissions($admin_role->rid, array('translate user-defined strings','translate admin strings'),'i18n_string');
break;
}
}
//grab all languages if need be to be used in this module
$languages = db_query('SELECT language FROM {languages}')->fetchAll();
//setup content types
$node_type = db_query('SELECT type FROM {node_type} WHERE base = :base', array(':base' => 'node_content'))->fetchAll();
foreach ($node_type as $key) {
$publish_type = 'language_content_type_' . $key->type;
$node_type_setting = db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => $publish_type))->fetchField();
$value = unserialize($node_type_setting);
//set to 2 for Enabled - With Translation
if ($value != '2') {
$value = '2';
db_update('variable')
->fields(array('value' => serialize($value)))
->condition('name', $publish_type)
->execute();
}
$multi_setting = 'i18n_node_options_' . $key->type;
$multi_record = db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => $multi_setting))->fetchField();
$multi_value = unserialize($multi_record);
$change = FALSE;
//set to Set current language as default for new content & Require language (Do not allow Language Neutral).
if(!empty($multi_value)) {
if ($multi_value[0] != 'current') {
$multi_value[0] = 'current';
$change = TRUE;
}
if ($multi_value[1] != 'required') {
$multi_value[1] = 'required';
$change = TRUE;
}
if ($change) {
db_update('variable')
->fields(array('value' => serialize($multi_value)))
->condition('name', $multi_setting)
->execute();
}
} else {
$multi_value = array('0' => 'current', '1' => 'required');
db_insert('variable')
->fields(array(
'value' => serialize($multi_value),
'name' => $multi_setting,
))
->execute();
}
}
//setup nodes to display english not language neutral
$nodes = db_query('SELECT nid FROM {node} WHERE language = :lang', array(':lang' => 'und'))->fetchAll();
foreach ($nodes as $key) {
$nid = $key->nid;
db_update('node')
->fields(array('language' => 'en'))
->condition('nid', $nid)
->execute();
}
//update taxonomy, FPP, etc in the entity translation table to display english not language neutral
$vocab = db_query('SELECT vid FROM {taxonomy_vocabulary} WHERE language = :lang', array(':lang' => 'und'))->fetchAll();
foreach ($vocab as $key) {
$vid = $key->vid;
db_update('taxonomy_vocabulary')
->fields(array('language' => 'en'))
->condition('vid', $vid)
->execute();
}
$term = db_query('SELECT tid FROM {taxonomy_term_data} WHERE language = :lang', array(':lang' => 'und'))->fetchAll();
foreach ($term as $key) {
$tid = $key->tid;
db_update('taxonomy_term_data')
->fields(array('language' => 'en'))
->condition('tid', $tid)
->execute();
}
$entities = db_query('SELECT entity_id FROM {entity_translation} WHERE language = :lang', array(':lang' => 'und'))->fetchAll();
foreach ($entities as $key) {
$eid = $key->entity_id;
db_update('entity_translation')
->fields(array('language' => 'en'))
->condition('entity_id', $eid)
->execute();
}
//Adjust redirects for english only
$redirects = db_query('SELECT rid FROM {redirect} WHERE language = :lang', array(':lang' => 'und'))->fetchAll();
foreach ($redirects as $key) {
$rid = $key->rid;
db_update('redirect')
->fields(array('language' => 'en'))
->condition('rid', $rid)
->execute();
}
//Setup blocks for translation
$blocks = db_query('SELECT module,delta FROM {block} WHERE i18n_mode = :mode', array(':mode' => 0))->fetchAll();
foreach ($blocks as $key) {
$bid = $key->module;
$bdel = $key->delta;
db_update('block')
->fields(array('i18n_mode' => 1))
->condition('module', $bid)
->execute();
$block_lang = db_query('SELECT delta FROM {i18n_block_language}')->fetchAll();
$block_check = array();
foreach ($block_lang as $key) {
$block_check[] = $key->delta;
}
if (!in_array($bdel, $block_check)) {
foreach ($languages as $key) {
db_insert('i18n_block_language')
->fields(array(
'module' => $bid,
'delta' => $bdel,
'language' => $key->language,
))
->execute();
}
}
}
//setup menus
$menus = db_query('SELECT menu_name FROM {menu_custom} WHERE i18n_mode = :mode', array(':mode' => 0))->fetchAll();
foreach ($menus as $key) {
$mid = $key->menu_name;
db_update('menu_custom')
->fields(array('i18n_mode' => 5))
->condition('menu_name', $mid)
->execute();
}
$menu_links = db_query('SELECT mlid FROM {menu_links} WHERE language = :lang', array(':lang' => 'und'))->fetchAll();
foreach ($menu_links as $key) {
$mlid = $key->mlid;
db_update('menu_links')
->fields(array('language' => 'en'))
->condition('mlid', $mlid)
->execute();
}
//FPP Entity Translation
$fpp = db_query('SELECT fpid FROM {fieldable_panels_panes} WHERE language = :lang', array(':lang' => 'und'))->fetchAll();
foreach ($fpp as $key) {
$fpid = $key->fpid;
db_update('fieldable_panels_panes')
->fields(array('language' => 'en'))
->condition('fpid', $fpid)
->execute();
}
/* views - add filter for current language
* @todo
* THIS IS JUST THE BASE CODE TO POSSIBLY CHANGE A VIEW
* WHEN WE HAVE A UIFOR THE CHECKLIST WE CAN HAVE THE USERS CHOOSE
* RIGHT NOW ITS TOO RISKY TO DO ALL
*
*
* $views = views_get_all_views();
* $view = views_get_view($view_name, TRUE);
* Filter criterion: Content: Language
* $handler->display->display_options['filters']['language']['id'] = 'language';
* $handler->display->display_options['filters']['language']['table'] = 'node';
* $handler->display->display_options['filters']['language']['field'] = 'language';
* $handler->display->display_options['filters']['language']['value'] = array(
* '***CURRENT_LANGUAGE***' => '***CURRENT_LANGUAGE***',
* );
* views_save_view($view); */
}