1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Common pages for the Media module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* CTools modal callback for editing a file.
|
10
|
*/
|
11
|
function media_file_edit_modal($form, &$form_state, $file, $js) {
|
12
|
ctools_include('modal');
|
13
|
ctools_include('ajax');
|
14
|
|
15
|
// If entity translation is enabled for the file entities and we have parent
|
16
|
// entity form/source langcodes, use them for the currently edited file.
|
17
|
if (!empty($_GET['media_parent_entity_form_langcode']) && is_string($_GET['media_parent_entity_form_langcode']) && module_invoke('entity_translation', 'enabled', 'file', $file)) {
|
18
|
$languages = language_list();
|
19
|
if (isset($languages[$_GET['media_parent_entity_form_langcode']])) {
|
20
|
$langcode = $_GET['media_parent_entity_form_langcode'];
|
21
|
$translation_handler = entity_translation_get_handler('file', $file);
|
22
|
$translation_handler->setActiveLanguage($langcode);
|
23
|
$translations = $translation_handler->getTranslations();
|
24
|
if (!isset($translations->data[$langcode])) {
|
25
|
if (!empty($_GET['media_parent_entity_source_langcode']) && is_string($_GET['media_parent_entity_source_langcode']) && isset($translations->data[$_GET['media_parent_entity_source_langcode']])) {
|
26
|
$source_langcode = $_GET['media_parent_entity_source_langcode'];
|
27
|
}
|
28
|
else {
|
29
|
$source_langcode = $translation_handler->getLanguage();
|
30
|
}
|
31
|
$translation_handler->setSourceLanguage($source_langcode);
|
32
|
}
|
33
|
}
|
34
|
}
|
35
|
|
36
|
$form_state['ajax'] = $js;
|
37
|
form_load_include($form_state, 'inc', 'file_entity', 'file_entity.pages');
|
38
|
|
39
|
$output = ctools_modal_form_wrapper('file_entity_edit', $form_state);
|
40
|
|
41
|
if ($js) {
|
42
|
$commands = $output;
|
43
|
|
44
|
if ($form_state['executed']) {
|
45
|
$commands = array(ctools_modal_command_dismiss(t('File saved')));
|
46
|
$preview = media_get_thumbnail_preview($file);
|
47
|
$commands[] = ajax_command_replace('.media-item[data-fid=' . $file->fid . ']', render($preview));
|
48
|
}
|
49
|
|
50
|
print ajax_render($commands);
|
51
|
exit();
|
52
|
}
|
53
|
|
54
|
// Otherwise, just return the output.
|
55
|
return $output;
|
56
|
}
|