1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Rules i18n integration.
|
6
|
*/
|
7
|
|
8
|
|
9
|
/**
|
10
|
* Implements hook_menu().
|
11
|
*/
|
12
|
function rules_i18n_rules_ui_menu_alter(&$items, $base_path, $base_count) {
|
13
|
|
14
|
$items[$base_path . '/manage/%rules_config/edit'] = array(
|
15
|
'title' => 'Edit',
|
16
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
17
|
'weight' => -100,
|
18
|
);
|
19
|
|
20
|
// For reaction-rules i18n generates the menu items, for the others we provide
|
21
|
// further i18n menu items for all other base paths.
|
22
|
|
23
|
if ($base_path != 'admin/config/workflow/rules/reaction') {
|
24
|
|
25
|
$items[$base_path . '/manage/%rules_config/translate'] = array(
|
26
|
'title' => 'Translate',
|
27
|
'page callback' => 'i18n_page_translate_localize',
|
28
|
'page arguments' => array('rules_config', $base_count + 1),
|
29
|
'access callback' => 'i18n_object_translate_access',
|
30
|
'access arguments' => array('rules_config', $base_count + 1),
|
31
|
'type' => MENU_LOCAL_TASK,
|
32
|
'file' => 'i18n.pages.inc',
|
33
|
'file path' => drupal_get_path('module', 'i18n'),
|
34
|
'weight' => 10,
|
35
|
);
|
36
|
|
37
|
$items[$base_path . '/manage/%rules_config/translate/%i18n_language'] = array(
|
38
|
'title' => 'Translate',
|
39
|
'page callback' => 'i18n_page_translate_localize',
|
40
|
'page arguments' => array('rules_config', $base_count + 1, $base_count + 3),
|
41
|
'access callback' => 'i18n_object_translate_access',
|
42
|
'access arguments' => array('rules_config', $base_count),
|
43
|
'type' => MENU_CALLBACK,
|
44
|
'file' => 'i18n.pages.inc',
|
45
|
'file path' => drupal_get_path('module', 'i18n'),
|
46
|
'weight' => 10,
|
47
|
);
|
48
|
}
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Implements hook_entity_info_alter().
|
53
|
*/
|
54
|
function rules_i18n_entity_info_alter(&$info) {
|
55
|
// Enable i18n support via the entity API.
|
56
|
$info['rules_config']['i18n controller class'] = 'RulesI18nStringController';
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* Implements hook_rules_config_insert().
|
61
|
*/
|
62
|
function rules_i18n_rules_config_insert($rules_config) {
|
63
|
// Do nothing when rebuilding defaults to avoid multiple cache rebuilds.
|
64
|
// @see rules_i18n_rules_config_defaults_rebuild()
|
65
|
if (!empty($rules_config->is_rebuild)) {
|
66
|
return;
|
67
|
}
|
68
|
|
69
|
i18n_string_object_update('rules_config', $rules_config);
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Implements hook_rules_config_update().
|
74
|
*/
|
75
|
function rules_i18n_rules_config_update($rules_config, $original = NULL) {
|
76
|
// Do nothing when rebuilding defaults to avoid multiple cache rebuilds.
|
77
|
// @see rules_i18n_rules_config_defaults_rebuild()
|
78
|
if (!empty($rules_config->is_rebuild)) {
|
79
|
return;
|
80
|
}
|
81
|
$original = $original ? $original : $rules_config->original;
|
82
|
|
83
|
// Account for name changes.
|
84
|
if ($original->name != $rules_config->name) {
|
85
|
i18n_string_update_context("rules:rules_config:{$original->name}:*", "rules:rules_config:{$rules_config->name}:*");
|
86
|
}
|
87
|
|
88
|
// We need to remove the strings of any disappeared properties, i.e. strings
|
89
|
// from translatable parameters of deleted actions.
|
90
|
|
91
|
// i18n_object() uses a static cache per config, so bypass it to wrap the
|
92
|
// original entity.
|
93
|
$object_key = i18n_object_key('rules_config', $original);
|
94
|
$old_i18n_object = new RulesI18nStringObjectWrapper('rules_config', $object_key, $original);
|
95
|
$old_strings = $old_i18n_object->get_strings(array('empty' => TRUE));
|
96
|
|
97
|
// Note: For the strings to have updated values, the updated entity needs to
|
98
|
// be handled last due to i18n's cache.
|
99
|
$strings = i18n_object('rules_config', $rules_config)->get_strings(array('empty' => TRUE));
|
100
|
|
101
|
foreach (array_diff_key($old_strings, $strings) as $name => $string) {
|
102
|
$string->remove(array('empty' => TRUE));
|
103
|
}
|
104
|
// Now update the remaining strings.
|
105
|
foreach ($strings as $string) {
|
106
|
$string->update(array('empty' => TRUE, 'update' => TRUE));
|
107
|
}
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Implements hook_rules_config_delete().
|
112
|
*/
|
113
|
function rules_i18n_rules_config_delete($rules_config) {
|
114
|
i18n_string_object_remove('rules_config', $rules_config);
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Implements hook_rules_config_defaults_rebuild().
|
119
|
*/
|
120
|
function rules_i18n_rules_config_defaults_rebuild($rules_configs, $originals) {
|
121
|
// Once all defaults have been rebuilt, update all i18n strings at once. That
|
122
|
// way we build the rules cache once the rebuild is complete and avoid
|
123
|
// rebuilding caches for each updated rule.
|
124
|
foreach ($rules_configs as $name => $rule_config) {
|
125
|
if (empty($originals[$name])) {
|
126
|
rules_i18n_rules_config_insert($rule_config);
|
127
|
}
|
128
|
else {
|
129
|
rules_i18n_rules_config_update($rule_config, $originals[$name]);
|
130
|
}
|
131
|
}
|
132
|
}
|