-
Notifications
You must be signed in to change notification settings - Fork 1
/
tinymce.admin.inc
169 lines (160 loc) · 5.9 KB
/
tinymce.admin.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
<?php
/**
* @file
* Admin form handling for TinyMCE module.
*/
/**
* Custom callback for filter form.
*
* @param stdClass $format
* Filter format.
*/
function _tinymce_settings_form(array &$form, array $form_state, $format) {
$form['#validate'][] = '_tinymce_settings_form_validate';
$elements = array();
$settings = $format->editor_settings;
$elements['tabs'] = array(
'#type' => 'vertical_tabs',
);
$elements['tabs']['tinymce_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Editor settings'),
'#parents' => array('editor_settings', 'tinymce_settings'),
);
$options = _tinymce_get_profile_options();
$existing_value = $settings['tinymce_settings']['profile'];
if (!array_key_exists($existing_value, $options)) {
backdrop_set_message(t('The editor profile %value does not exist, falling back to "default" profile.', array(
'%value' => $existing_value,
)), 'warning');
$existing_value = 'default';
}
$elements['tabs']['tinymce_settings']['profile'] = array(
'#title' => t('Editor profile'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $existing_value,
);
$elements['tabs']['tinymce_settings']['skin'] = array(
'#title' => t('Editor skin'),
'#type' => 'select',
'#options' => array(
'oxide' => t('Light'),
'oxide-dark' => t('Dark'),
),
'#default_value' => $settings['tinymce_settings']['skin'],
);
$elements['tabs']['tinymce_settings']['content_css'] = array(
'#title' => t('Content CSS files'),
'#type' => 'textarea',
'#default_value' => $settings['tinymce_settings']['content_css'],
'#rows' => 3,
'#attributes' => array(
'placeholder' => '/core/themes/basis/css/skin.css',
),
'#description' => t('Add URLs to CSS files, the editor should use to display its content, one file per line.<br>If a file is named <code>tinymce-styles-dropdown.css</code>, this file additionally gets parsed for items to append to the toolbar styles dropdown.'),
);
$elements['tabs']['image_browser'] = array(
'#type' => 'fieldset',
'#title' => t('Image browser'),
'#parents' => array('editor_settings', 'image_browser'),
);
$elements['tabs']['image_browser']['enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable image browser'),
'#default_value' => $settings['image_browser']['enable'],
);
$elements['tabs']['image_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Image upload'),
);
$elements['tabs']['image_settings']['image'] = filter_editor_image_upload_settings_form($format);
$elements['tabs']['image_settings']['image']['#parents'] = array(
'editor_settings',
'image_upload',
);
$elements['tabs']['image_settings']['image']['status']['#description'] = _tinymce_settings_status_description('image');
$elements['tabs']['file_settings'] = array(
'#type' => 'fieldset',
'#title' => t('File upload'),
);
$elements['tabs']['file_settings']['file'] = filter_editor_file_upload_settings_form($format);
$elements['tabs']['file_settings']['file']['#parents'] = array(
'editor_settings',
'file_upload',
);
$elements['tabs']['file_settings']['file']['status']['#description'] = _tinymce_settings_status_description('file');
return $elements;
}
/**
* Validation callback for settings form.
*/
function _tinymce_settings_form_validate(array $form, array &$form_state) {
unset($form_state['values']['editor_settings']['tabs']);
if (!empty($form_state['values']['editor_settings']['tinymce_settings']['content_css'])) {
$content_css = trim($form_state['values']['editor_settings']['tinymce_settings']['content_css']);
$files = explode("\n", $content_css);
$files_trimmed = array();
foreach ($files as $file) {
$file = trim($file);
if (!preg_match('/.+\.css$/', $file)) {
form_set_error('editor_settings][tinymce_settings][content_css', t('At least one URL to content CSS does not end with ".css".'));
}
if (!valid_url($file, TRUE) && !valid_url($file, FALSE)) {
form_set_error('editor_settings][tinymce_settings][content_css', t('At least one URL to content CSS is invalid.'));
}
$files_trimmed[] = $file;
}
$form_state['values']['editor_settings']['tinymce_settings']['content_css'] = implode("\n", $files_trimmed);
}
}
/**
* Custom callback to return options list for admin form.
*
* @return array
*/
function _tinymce_get_profile_options() {
$options = array();
$all_profiles = config_get_names_with_prefix('tinymce.profile');
foreach ($all_profiles as $config_name) {
$config = config($config_name);
$profile_name = $config->get('name');
$options[$profile_name] = check_plain($config->get('label'));
}
return $options;
}
/**
* Helper callback to provide a form description for upload setting.
*
* @param string $type
* @return string
*/
function _tinymce_settings_status_description($type) {
// This link hint might get obsolete, if core Filter module provides the
// permission matrix directly in this form.
if (user_access('administer permissions')) {
if ($type == 'image') {
$help = t('Allow roles with <a href="!url">sufficient permissions</a> to upload via editor image dialog and drag and drop.', array(
'!url' => url('admin/config/people/permissions', array(
'query' => array('search' => 'filter'),
)),
));
}
else {
$help = t('Allow roles with <a href="!url">sufficient permissions</a> to upload files via editor link dialog.', array(
'!url' => url('admin/config/people/permissions', array(
'query' => array('search' => 'filter'),
)),
));
}
}
else {
if ($type == 'image') {
$help = t('Allow roles with sufficient permissions to upload via editor image dialog and drag and drop.');
}
else {
$help = t('Allow roles with sufficient permissions to upload files via editor link dialog.');
}
}
return $help;
}