-
Notifications
You must be signed in to change notification settings - Fork 1
/
tinymce.install
89 lines (84 loc) · 2.85 KB
/
tinymce.install
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
<?php
/**
* @file
* TinyMCE module update hooks.
*/
/**
* Update config for default and full profile.
*/
function tinymce_update_1000() {
$path = backdrop_get_path('module', 'tinymce') . '/config/';
$config_profile_default = config('tinymce.profiles.default');
$contents = file_get_contents($path . 'tinymce.profiles.default.json');
$data = json_decode($contents, TRUE);
$config_profile_default->set('tiny_options.toolbar', $data['tiny_options']['toolbar']);
$config_profile_default->set('tiny_options.plugins', $data['tiny_options']['plugins']);
$config_profile_default->save();
$config_profile_full = config('tinymce.profiles.full');
$contents = file_get_contents($path . 'tinymce.profiles.full.json');
$data = json_decode($contents, TRUE);
$config_profile_full->set('tiny_options.toolbar', $data['tiny_options']['toolbar']);
$config_profile_full->set('tiny_options.plugins', $data['tiny_options']['plugins']);
$config_profile_full->save();
}
/**
* Add br tags to profiles and filter allowlist if not set yet.
*/
function tinymce_update_1001() {
// Update TinyMCE profiles if necessary.
$all_profiles = config_get_names_with_prefix('tinymce.profile');
foreach ($all_profiles as $config_name) {
$config = config($config_name);
$taglist = $config->get('filter_allowed_html');
if ($taglist) {
$tags = explode(',', $taglist);
if (!in_array('br', $tags)) {
$tags[] = 'br';
$allowlist = implode(',', $tags);
$config->set('filter_allowed_html', $allowlist);
$config->save();
}
}
}
// Update filter formats if necessary.
$all_formats = config_get_names_with_prefix('filter.format');
foreach ($all_formats as $config_name) {
$config = config($config_name);
if ($config->get('editor') != 'tinymce') {
continue;
}
if ($filter_html = $config->get('filters.filter_html')) {
if (!$filter_html['status']) {
continue;
}
$allowlist = $filter_html['settings']['allowed_html'];
$tags = explode(' ', $allowlist);
if (!in_array('<br>', $tags)) {
$tags[] = '<br>';
$allowlist = trim(implode(' ', $tags));
$config->set('filters.filter_html.settings.allowed_html', $allowlist);
$config->save();
}
}
}
}
/**
* Add list properties context menu setting to default profiles.
*/
function tinymce_update_1002() {
$profiles = array(
'tinymce.profiles.default' => 'backdropimage backdroplink',
'tinymce.profiles.full' => 'backdroplink backdropimage',
);
foreach ($profiles as $profile => $orig_value) {
$config = config($profile);
if ($config->isNew()) {
continue;
}
$current_value = $config->get('tiny_options.contextmenu');
if ($current_value == $orig_value) {
$config->set('tiny_options.contextmenu', $orig_value . ' backdroplistprops');
$config->save();
}
}
}