-
Notifications
You must be signed in to change notification settings - Fork 6
/
tmgmt.rules.inc
247 lines (233 loc) · 6.86 KB
/
tmgmt.rules.inc
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
* @file
* Rules integration.
*/
/**
* {@inheritdoc}
*/
function tmgmt_rules_action_info() {
$info['tmgmt_rules_job_request_translation'] = array(
'label' => t('Request Job translation'),
'group' => t('Translation Management'),
'parameter' => array(
'job' => array(
'type' => 'tmgmt_job',
'label' => t('Translation Job'),
'description' => t('The translation job for which translations should be requested.'),
),
),
'access callback' => 'tmgmt_rules_job_submit_access',
);
$info['tmgmt_rules_job_accept_translation'] = array(
'label' => t('Accept Job translation'),
'group' => t('Translation Management'),
'parameter' => array(
'job' => array(
'type' => 'tmgmt_job',
'label' => t('Translation Job'),
'description' => t('The translation job for which translations should be accepted.'),
),
'message' => array(
'type' => 'text',
'label' => t('An optional message'),
'description' => t('Will be stored in the job message and displayed to the user.'),
'optional' => TRUE,
),
),
'access callback' => 'tmgmt_rules_job_accept_translation_access',
);
$info['tmgmt_rules_job_abort_translation'] = array(
'label' => t('Abort translation job'),
'group' => t('Translation Management'),
'parameter' => array(
'job' => array(
'type' => 'tmgmt_job',
'label' => t('Translation Job'),
'description' => t('The translation job that should be aborted.'),
),
),
'access callback' => 'tmgmt_rules_job_submit_access',
);
$info['tmgmt_rules_job_delete'] = array(
'label' => t('Delete Job'),
'group' => t('Translation Management'),
'parameter' => array(
'job' => array(
'type' => 'tmgmt_job',
'label' => t('Translation Job'),
'description' => t('The translation job that should be deleted.'),
),
),
'access callback' => 'tmgmt_rules_job_delete_access',
);
$info['tmgmt_rules_job_checkout'] = array(
'label' => t('Checkout a job'),
'group' => t('Translation Management'),
'parameter' => array(
'job' => array(
'type' => 'tmgmt_job',
'label' => t('Translation Job'),
'description' => t('The translation job that should be checked out.'),
),
),
'access callback' => 'tmgmt_rules_job_submit_access',
);
$info['tmgmt_get_first_from_node_list'] = array(
'label' => t('Get first item from a list of nodes'),
'group' => t('Data'),
'parameter' => array(
'list' => array(
'type' => 'list<node>',
'label' => t('List'),
'restriction' => 'selector',
),
),
'provides' => array(
'first_node' => array(
'type' => 'node',
'label' => t('Node'),
),
),
);
$info['tmgmt_rules_create_job'] = array(
'label' => t('Create a job for a given source language'),
'group' => t('Translation Management'),
'parameter' => array(
'source_language' => array(
'type' => 'text',
'label' => t('Source Language'),
'description' => t('The language from which should be translated'),
'options list' => 'entity_metadata_language_list',
),
),
'provides' => array(
'job' => array(
'label' => t('Job'),
'type' => 'tmgmt_job',
),
),
);
$info['tmgmt_rules_job_add_item'] = array(
'label' => t('Add an item to a job'),
'group' => t('Translation Management'),
'parameter' => array(
'job' => array(
'type' => 'tmgmt_job',
'label' => t('Translation Job'),
'description' => t('The translation job that should be canceled.'),
),
'plugin' => array(
'type' => 'token',
'label' => t('Source plugin'),
'description' => t('The source plugin of this item'),
//'options list' => 'entity_metadata_language_list',
),
'item_type' => array(
'type' => 'token',
'label' => t('Item type'),
'description' => t('The item type'),
//'options list' => 'entity_metadata_language_list',
),
'item_id' => array(
'type' => 'text',
'label' => t('Item ID'),
'description' => t('ID of the referenced item'),
),
),
);
return $info;
}
/**
* Rules callback to request a translation of a job.
*/
function tmgmt_rules_job_request_translation(TMGMTJob $job) {
if ($job->isTranslatable()) {
$job->requestTranslation();
}
}
/**
* Rules callback to accept a translation of a job.
*/
function tmgmt_rules_job_accept_translation(TMGMTJob $job, $message) {
foreach ($job->getItems() as $item) {
if ($item->isNeedsReview()) {
$item->acceptTranslation();
}
}
}
/**
* Rules callback to cancel a translation job.
*/
function tmgmt_rules_job_abort_translation(TMGMTJob $job) {
$job->abortTranslation();
}
/**
* Rules callback to redirect to a translation job.
*/
function tmgmt_rules_job_checkout(TMGMTJob $job) {
$redirects = tmgmt_ui_job_checkout_multiple(array($job));
// If necessary, do a redirect.
if ($redirects) {
tmgmt_ui_redirect_queue_set($redirects, current_path());
drupal_goto(tmgmt_ui_redirect_queue_dequeue());
// Count of the job messages is one less due to the final redirect.
drupal_set_message(format_plural(count($redirects), t('One job needs to be checked out.'), t('@count jobs need to be checked out.')));
}
}
/**
* Rules callback to get the job for a specific language combination.
*/
function tmgmt_rules_create_job($source_language) {
return array(
'job' => tmgmt_job_create($source_language, ''),
);
}
/**
* Rules callback to add an item to a job.
*/
function tmgmt_rules_job_add_item(TMGMTJob $job, $plugin, $item_type, $item_id) {
try {
$job->addItem($plugin, $item_type, $item_id);
}
catch (TMGMTException $e) {
watchdog_exception('tmgmt', $e);
drupal_set_message(t('Unable to add job item of type %type with id %id. Make sure the source content is not empty.',
array('%type' => $item_type, '%id' => $item_id)), 'error');
}
}
/**
* Rules action to extract the first node from a node list.
*/
function tmgmt_get_first_from_node_list($list) {
return array(
'first_node' => reset($list),
);
}
/**
* Rules action to delete a translation job.
*/
function tmgmt_rules_job_delete(TMGMTJob $job) {
// Prevent users without job delete permission to be able to delete jobs.
if (tmgmt_job_access('delete')) {
$job->delete();
}
}
/**
* Checks access to rules job delete action.
*/
function tmgmt_rules_job_delete_access() {
return tmgmt_job_access('delete');
}
/**
* Checks access to rules job submit like actions.
*/
function tmgmt_rules_job_submit_access() {
return tmgmt_job_access('submit');
}
/**
* Checks access to rules accept translation action.
*/
function tmgmt_rules_job_accept_translation_access() {
return tmgmt_job_access('accept');
}