Mercurial > hg > rr-repo
comparison sites/all/modules/wysiwyg/wysiwyg.features.inc @ 0:ff03f76ab3fe
initial version
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Wed, 21 Aug 2013 18:51:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ff03f76ab3fe |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Implements hook_features_export_options(). | |
5 */ | |
6 function wysiwyg_features_export_options() { | |
7 $profiles = array(); | |
8 | |
9 // Get human-readable name from filter module. | |
10 $formats = filter_formats(); | |
11 | |
12 foreach (array_keys(wysiwyg_profile_load_all()) as $format) { | |
13 // Text format may vanish without deleting the wysiwyg profile. | |
14 if (isset($formats[$format])) { | |
15 $profiles[$format] = $formats[$format]->name; | |
16 } | |
17 } | |
18 return $profiles; | |
19 } | |
20 | |
21 /** | |
22 * Implements hook_features_export(). | |
23 */ | |
24 function wysiwyg_features_export($data, &$export, $module_name = '') { | |
25 $pipe = array(); | |
26 | |
27 // The wysiwyg_default_formats() hook integration is provided by the | |
28 // features module so we need to add it as a dependency. | |
29 $export['dependencies']['features'] = 'features'; | |
30 $export['dependencies']['wysiwyg'] = 'wysiwyg'; | |
31 | |
32 foreach ($data as $name) { | |
33 if ($profile = wysiwyg_get_profile($name)) { | |
34 // Add profile to exports. | |
35 $export['features']['wysiwyg'][$profile->format] = $profile->format; | |
36 | |
37 // Chain filter format for export. | |
38 $pipe['filter'][] = $profile->format; | |
39 } | |
40 } | |
41 | |
42 return $pipe; | |
43 } | |
44 | |
45 /** | |
46 * Implements hook_features_export_render(). | |
47 */ | |
48 function wysiwyg_features_export_render($module, $data, $export = NULL) { | |
49 $code = array(); | |
50 $code[] = ' $profiles = array();'; | |
51 $code[] = ''; | |
52 | |
53 foreach ($data as $name) { | |
54 if ($profile = wysiwyg_get_profile($name)) { | |
55 $profile_export = features_var_export($profile, ' '); | |
56 $profile_identifier = features_var_export($profile->format); | |
57 $code[] = " // Exported profile: {$profile->format}"; | |
58 $code[] = " \$profiles[{$profile_identifier}] = {$profile_export};"; | |
59 $code[] = ""; | |
60 } | |
61 } | |
62 | |
63 $code[] = ' return $profiles;'; | |
64 $code = implode("\n", $code); | |
65 return array('wysiwyg_default_profiles' => $code); | |
66 } | |
67 | |
68 /** | |
69 * Implements hook_features_revert(). | |
70 */ | |
71 function wysiwyg_features_revert($module) { | |
72 return wysiwyg_features_rebuild($module); | |
73 } | |
74 | |
75 /** | |
76 * Implements hook_features_rebuild(). | |
77 */ | |
78 function wysiwyg_features_rebuild($module) { | |
79 if ($defaults = features_get_default('wysiwyg', $module)) { | |
80 foreach ($defaults as $profile) { | |
81 db_merge('wysiwyg') | |
82 ->key(array('format' => $profile['format'])) | |
83 ->fields(array( | |
84 'editor' => $profile['editor'], | |
85 'settings' => serialize($profile['settings']), | |
86 )) | |
87 ->execute(); | |
88 } | |
89 wysiwyg_profile_cache_clear(); | |
90 } | |
91 } | |
92 |