forked from sprice/wysiwyg_features
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwysiwyg_features.module
116 lines (108 loc) · 3.13 KB
/
wysiwyg_features.module
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
<?php
/**
* @file
* Features support.
* Wysiwyg Features integration
*/
/**
* Implements hook_features_api().
*/
function wysiwyg_features_features_api() {
return array(
'wysiwyg' => array(
'name' => t('Wysiwyg profiles'),
'default_hook' => 'features_default_wysiwyg',
'default_file' => FEATURES_DEFAULTS_INCLUDED,
'feature_source' => TRUE,
),
);
}
/**
* Implements hook_features_export_options().
*/
function wysiwyg_features_export_options() {
$options = array();
foreach (wysiwyg_profile_load_all() as $editor => $info) {
if ($info->settings) {
$options[$editor] = $editor;
}
}
return $options;
}
/**
* Implements hook_features_export().
*/
function wysiwyg_features_export($data, &$export, $module_name = '') {
$export['dependencies']['features'] = 'features';
$export['dependencies']['wysiwyg'] = 'wysiwyg';
$export['dependencies']['wysiwyg_features'] = 'wysiwyg_features';
foreach ($data as $option) {
$profile = wysiwyg_profile_load($option);
$export['features']['wysiwyg'][$profile->format]['format'] = $profile->format;
$export['features']['wysiwyg'][$profile->format]['editor'] = $profile->editor;
$export['features']['wysiwyg'][$profile->format]['settings'] = $profile->settings;
}
$pipe = array();
return $pipe;
}
/**
* Implements hook_features_export_render().
*/
function wysiwyg_features_export_render($module, $data, $export = NULL) {
$code = array();
$wysiwyg_export = features_var_export($data, ' ');
$code[] = " \$profiles = {$wysiwyg_export};";
$code[] = "";
$code[] = ' return $profiles;';
$code = implode("\n", $code);
return array('features_default_wysiwyg' => $code);
}
/**
* Implements hook_features_export_revert().
*/
function wysiwyg_features_revert($module) {
wysiwyg_features_rebuild($module);
}
/**
* Implements hook_features_export_rebuild().
*/
function wysiwyg_features_rebuild($module) {
$defaults = module_invoke($module, 'features_default_wysiwyg');
if (!empty($defaults)) {
foreach ($defaults as $default) {
$num_updated = db_update('wysiwyg')
->fields(array(
'format' => $default['format'],
'editor' => $default['editor'],
'settings' => serialize($default['settings']),
))
->condition('format', $default['format'])
->execute();
if (!$num_updated) {
db_insert('wysiwyg')
->fields(array(
'format' => $default['format'],
'editor' => $default['editor'],
'settings' => serialize($default['settings']),
))
->execute();
}
}
}
}
/**
* Loads all current wysiwyg profiles
*/
function features_wysiwyg_load() {
// Use machine name for retrieving the format if available.
$all_profiles = wysiwyg_profile_load_all();
$profiles = array();
foreach ($all_profiles as $profile) {
if (!empty($profile->settings)) {
$profiles[$profile->name]['format'] = $profile->format;
$profiles[$profile->name]['editor'] = $profile->editor;
$profiles[$profile->name]['settings'] = $profile->settings;
}
}
return $profiles;
}