1 |
ca0757b9
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Common pages for the Media WYSIWYG module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Form callback used when embedding media.
|
10 |
|
|
*
|
11 |
|
|
* Allows the user to pick a format for their media file.
|
12 |
|
|
* Can also have additional params depending on the media type.
|
13 |
|
|
*/
|
14 |
|
|
function media_wysiwyg_format_form($form, &$form_state, $file) {
|
15 |
|
|
$form_state['file'] = $file;
|
16 |
|
|
|
17 |
|
|
// Allow for overrides to the fields.
|
18 |
|
|
$query_fields = isset($_GET['fields']) ? drupal_json_decode($_GET['fields']) : array();
|
19 |
|
|
$fields = media_wysiwyg_filter_field_parser(array('fields' => $query_fields), $file);
|
20 |
|
|
|
21 |
|
|
$view_modes = media_wysiwyg_get_wysiwyg_allowed_view_modes($file);
|
22 |
|
|
$formats = $options = array();
|
23 |
|
|
foreach ($view_modes as $view_mode => $view_mode_info) {
|
24 |
|
|
// @TODO: Display more verbose information about which formatter and what it
|
25 |
|
|
// does.
|
26 |
|
|
$options[$view_mode] = $view_mode_info['label'];
|
27 |
|
|
$element = media_wysiwyg_get_file_without_label($file, $view_mode, array('wysiwyg' => TRUE));
|
28 |
|
|
|
29 |
|
|
// Make a pretty name out of this.
|
30 |
|
|
$formats[$view_mode] = drupal_render($element);
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
// Add the previews back into the form array so they can be altered.
|
34 |
|
|
$form['#formats'] = &$formats;
|
35 |
|
|
|
36 |
|
|
if (!count($formats)) {
|
37 |
|
|
throw new Exception('Unable to continue, no available formats for displaying media.');
|
38 |
|
|
return;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
// Allow for overrides to the display format.
|
42 |
|
|
$default_view_mode = is_array($query_fields) && isset($query_fields['format']) ? $query_fields['format'] : variable_get('media_wysiwyg_wysiwyg_default_view_mode', 'full');
|
43 |
|
|
if (!isset($formats[$default_view_mode])) {
|
44 |
|
|
$default_view_mode = key($formats);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
// Add the previews by reference so that they can easily be altered by
|
48 |
|
|
// changing $form['#formats'].
|
49 |
|
|
$settings['media']['formatFormFormats'] = &$formats;
|
50 |
|
|
$form['#attached']['js'][] = array('data' => $settings, 'type' => 'setting');
|
51 |
|
|
|
52 |
|
|
// Add the required libraries, JavaScript and CSS for the form.
|
53 |
|
|
$form['#attached']['library'][] = array('media', 'media_base');
|
54 |
|
|
$form['#attached']['library'][] = array('system', 'form');
|
55 |
|
|
$form['#attached']['css'][] = drupal_get_path('module', 'media_wysiwyg') . '/css/media_wysiwyg.css';
|
56 |
|
|
$form['#attached']['js'][] = drupal_get_path('module', 'media_wysiwyg') . '/js/media_wysiwyg.format_form.js';
|
57 |
|
|
|
58 |
|
|
$form['title'] = array(
|
59 |
|
|
'#markup' => t('Embedding %filename', array('%filename' => $file->filename)),
|
60 |
|
|
);
|
61 |
|
|
|
62 |
|
|
$preview = media_get_thumbnail_preview($file);
|
63 |
|
|
|
64 |
|
|
$form['preview'] = array(
|
65 |
|
|
'#type' => 'markup',
|
66 |
|
|
'#title' => check_plain(basename($file->uri)),
|
67 |
|
|
'#markup' => drupal_render($preview),
|
68 |
|
|
);
|
69 |
|
|
|
70 |
|
|
// These will get passed on to WYSIWYG.
|
71 |
|
|
$form['options'] = array(
|
72 |
|
|
'#type' => 'fieldset',
|
73 |
|
|
'#title' => t('options'),
|
74 |
|
|
);
|
75 |
|
|
|
76 |
|
|
$form['options']['format'] = array(
|
77 |
|
|
'#type' => 'select',
|
78 |
|
|
'#title' => t('Display as'),
|
79 |
|
|
'#options' => $options,
|
80 |
|
|
'#default_value' => $default_view_mode,
|
81 |
|
|
'#description' => t('Choose the type of display you would like for this
|
82 |
|
|
file. Please be aware that files may display differently than they do when
|
83 |
|
|
they are inserted into an editor.')
|
84 |
|
|
);
|
85 |
|
|
|
86 |
|
|
// Add fields from the file, so that we can override them if neccesary.
|
87 |
|
|
$form['options']['fields'] = array();
|
88 |
|
|
foreach ($fields as $field_name => $field_value) {
|
89 |
|
|
$file->{$field_name} = $field_value;
|
90 |
|
|
}
|
91 |
|
|
field_attach_form('file', $file, $form['options']['fields'], $form_state);
|
92 |
|
|
$instance = field_info_instances('file', $file->type);
|
93 |
|
|
foreach ($instance as $field_name => $field_value) {
|
94 |
|
|
if (isset($instance[$field_name]['settings']) && isset($instance[$field_name]['settings']['wysiwyg_override']) && !$instance[$field_name]['settings']['wysiwyg_override']) {
|
95 |
|
|
unset($form['options']['fields'][$field_name]);
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
// Similar to a form_alter, but we want this to run first so that
|
100 |
|
|
// media.types.inc can add the fields specific to a given type (like alt tags
|
101 |
|
|
// on media). If implemented as an alter, this might not happen, making other
|
102 |
|
|
// alters not be able to work on those fields.
|
103 |
|
|
// @todo: We need to pass in existing values for those attributes.
|
104 |
|
|
drupal_alter('media_wysiwyg_format_form_prepare', $form, $form_state, $file);
|
105 |
|
|
|
106 |
|
|
if (!element_children($form['options'])) {
|
107 |
|
|
$form['options']['#attributes'] = array('style' => 'display:none');
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
return $form;
|
111 |
|
|
} |