1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Installation file for i18nmenu module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_install().
|
10
|
*/
|
11
|
function i18n_menu_install() {
|
12
|
// Set module weight for it to run after core modules, but before views.
|
13
|
db_query("UPDATE {system} SET weight = 5 WHERE name = 'i18n_menu' AND type = 'module'");
|
14
|
module_load_install('i18n');
|
15
|
i18n_install_create_fields('menu_links', array('language', 'i18n_tsid'));
|
16
|
i18n_install_create_fields('menu_custom', array('language', 'i18n_mode'));
|
17
|
// If updating from D6, module changed name
|
18
|
if (variable_get('i18n_drupal6_update')) {
|
19
|
i18n_menu_update_7000();
|
20
|
}
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* Implements hook_uninstall().
|
25
|
*/
|
26
|
function i18n_menu_uninstall() {
|
27
|
db_drop_field('menu_links', 'language');
|
28
|
db_drop_field('menu_links', 'i18n_tsid');
|
29
|
db_drop_field('menu_custom', 'language');
|
30
|
db_drop_field('menu_custom', 'i18n_mode');
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* Implements hook_schema_alter().
|
35
|
*/
|
36
|
function i18n_menu_schema_alter(&$schema) {
|
37
|
$schema['menu_links']['fields']['language'] = array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => LANGUAGE_NONE);
|
38
|
$schema['menu_links']['fields']['i18n_tsid'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0);
|
39
|
$schema['menu_custom']['fields']['language'] = array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => LANGUAGE_NONE);
|
40
|
$schema['menu_custom']['fields']['i18n_mode'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Update menu items language field from Drupal 6
|
45
|
*/
|
46
|
function i18n_menu_update_7000() {
|
47
|
// @todo
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Set alter property for menu items with language.
|
52
|
*/
|
53
|
function i18n_menu_update_7001() {
|
54
|
// Compile a list of menus with i18n options.
|
55
|
$i18n_menus = array_filter(menu_get_names(), 'i18n_menu_mode');
|
56
|
if ($i18n_menus) {
|
57
|
$query = db_select('menu_links', 'm')
|
58
|
->fields('m')
|
59
|
->condition('menu_name', $i18n_menus);
|
60
|
foreach ($query->execute()->fetchAllAssoc('mlid', PDO::FETCH_ASSOC) as $mlid => $item) {
|
61
|
$options = unserialize($item['options']);
|
62
|
if (_i18n_menu_link_check_alter($item) && empty($options['alter'])) {
|
63
|
$options['alter'] = TRUE;
|
64
|
db_update('menu_links')
|
65
|
->condition('mlid', $mlid)
|
66
|
->fields(array('options' => serialize($options)))
|
67
|
->execute();
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
}
|