1 |
1e39edcb
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Functions related to features integration.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_features_api().
|
10 |
|
|
*/
|
11 |
|
|
function media_wysiwyg_features_api() {
|
12 |
|
|
return array(
|
13 |
|
|
'media_wysiwyg' => array(
|
14 |
|
|
'name' => t('Media WYSIWYG'),
|
15 |
|
|
'feature_source' => TRUE,
|
16 |
|
|
'default_hook' => 'media_wysiwyg_defaults',
|
17 |
|
|
'default_file' => FEATURES_DEFAULTS_INCLUDED,
|
18 |
|
|
),
|
19 |
|
|
);
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
/**
|
23 |
|
|
* Implements hook_features_export_options().
|
24 |
|
|
*
|
25 |
|
|
* Defines what shows up in the feature creation interface
|
26 |
|
|
*/
|
27 |
|
|
function media_wysiwyg_features_export_options() {
|
28 |
|
|
$options = array();
|
29 |
|
|
$entity_info = entity_get_info('file');
|
30 |
|
|
foreach ($entity_info['bundles'] as $file_type => $file_type_info) {
|
31 |
|
|
$file_type_label = check_plain($file_type_info['label']);
|
32 |
|
|
$options[$file_type . '_wysiwyg_view_mode'] =
|
33 |
|
|
t('@file_type WYSIWYG view mode', array('@file_type' => $file_type_label));
|
34 |
|
|
|
35 |
|
|
$view_mode_settings = field_view_mode_settings('file', $file_type);
|
36 |
|
|
foreach ($entity_info['view modes'] as $view_mode => $view_mode_info) {
|
37 |
|
|
if (!empty($view_mode_settings[$view_mode]['custom_settings'])) {
|
38 |
|
|
$options[$file_type . '_' . $view_mode . '_restrict_wysiwyg'] =
|
39 |
|
|
t('@file_type view mode restriction: @view_mode',
|
40 |
|
|
array('@file_type' => $file_type_label, '@view_mode' => $view_mode_info['label']));
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
// Add default option.
|
44 |
|
|
$options[$file_type . '_default_restrict_wysiwyg'] =
|
45 |
d1c64ea8
|
Assos Assos
|
t('@file_type view mode restriction: Default', array(
|
46 |
1e39edcb
|
Assos Assos
|
'@file_type' => $file_type_label,
|
47 |
|
|
));
|
48 |
|
|
}
|
49 |
|
|
return $options;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
/**
|
53 |
|
|
* Implements hook_features_export().
|
54 |
|
|
*/
|
55 |
|
|
function media_wysiwyg_features_export($data, &$export, $module_name = '') {
|
56 |
|
|
$export['dependencies']['media_wysiwyg'] = 'media_wysiwyg';
|
57 |
|
|
|
58 |
|
|
$entity_info = entity_get_info('file');
|
59 |
|
|
foreach ($entity_info['bundles'] as $file_type => $file_type_info) {
|
60 |
|
|
|
61 |
|
|
// Export the wysiwyg view mode setting for the file type.
|
62 |
|
|
$mode_data_key = $file_type . '_wysiwyg_view_mode';
|
63 |
|
|
if (in_array($mode_data_key, $data, TRUE)) {
|
64 |
|
|
$view_mode = _media_wysiwyg_get_wysiwyg_mode($file_type);
|
65 |
|
|
$export['features']['media_wysiwyg'][$mode_data_key] = $mode_data_key;
|
66 |
|
|
}
|
67 |
|
|
// Export the restricted view modes for the file type.
|
68 |
|
|
$view_modes = array_keys($entity_info['view modes']);
|
69 |
|
|
array_push($view_modes, 'default');
|
70 |
|
|
foreach ($view_modes as $view_mode) {
|
71 |
|
|
$restrict_data_key = $file_type . '_' . $view_mode . '_restrict_wysiwyg';
|
72 |
|
|
if (in_array($restrict_data_key, $data, TRUE)) {
|
73 |
|
|
$export['features']['media_wysiwyg'][$restrict_data_key] = $restrict_data_key;
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Implements hook_features_export_render().
|
81 |
|
|
*/
|
82 |
e4215af7
|
Assos Assos
|
function media_wysiwyg_features_export_render($module_name, $data, $export = NULL) {
|
83 |
1e39edcb
|
Assos Assos
|
$code = array();
|
84 |
|
|
$code[] = ' $media_wysiwyg = array();';
|
85 |
|
|
$code[] = '';
|
86 |
|
|
|
87 |
|
|
$entity_info = entity_get_info('file');
|
88 |
|
|
foreach ($entity_info['bundles'] as $file_type => $file_type_info) {
|
89 |
|
|
|
90 |
|
|
// Render the wysiwyg view mode setting for the file type.
|
91 |
|
|
$mode_data_key = $file_type . '_wysiwyg_view_mode';
|
92 |
|
|
if (array_key_exists($mode_data_key, $data) || in_array($mode_data_key, $data, TRUE)) {
|
93 |
|
|
$view_mode = _media_wysiwyg_get_wysiwyg_mode($file_type);
|
94 |
d1c64ea8
|
Assos Assos
|
$view_mode_export = (!empty($view_mode) ? features_var_export($view_mode) : "'none'");
|
95 |
1e39edcb
|
Assos Assos
|
$code[] = " // WYSIWYG view mode for $file_type files.";
|
96 |
|
|
$code[] = " \$media_wysiwyg['{$mode_data_key}'] = {$view_mode_export};";
|
97 |
|
|
$code[] = "";
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
// Export the restricted view modes for the file type.
|
101 |
|
|
$restriction_code = array();
|
102 |
|
|
$restricted_view_modes = _media_wysiwyg_get_restricted_modes($file_type);
|
103 |
|
|
$view_modes = array_keys($entity_info['view modes']);
|
104 |
|
|
array_push($view_modes, 'default');
|
105 |
|
|
foreach ($view_modes as $view_mode) {
|
106 |
|
|
$restrict_data_key = $file_type . '_' . $view_mode . '_restrict_wysiwyg';
|
107 |
|
|
if (array_key_exists($restrict_data_key, $data) || in_array($restrict_data_key, $data, TRUE)) {
|
108 |
|
|
$displays_export = in_array($view_mode, $restricted_view_modes) ? 'TRUE' : 'FALSE';
|
109 |
|
|
$restriction_code[] = " \$media_wysiwyg['{$restrict_data_key}'] = {$displays_export};";
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
if (!empty($restriction_code)) {
|
113 |
|
|
array_unshift($restriction_code, " // Restricted view modes for $file_type files.");
|
114 |
|
|
$restriction_code[] = "";
|
115 |
|
|
$code = array_merge($code, $restriction_code);
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
$code[] = ' return $media_wysiwyg;';
|
120 |
|
|
$code = implode("\n", $code);
|
121 |
|
|
|
122 |
|
|
return array('media_wysiwyg_defaults' => $code);
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
/**
|
126 |
|
|
* Implements hook_features_revert().
|
127 |
|
|
*/
|
128 |
|
|
function media_wysiwyg_features_revert($module) {
|
129 |
|
|
if ($defaults = features_get_default('media_wysiwyg', $module)) {
|
130 |
|
|
|
131 |
|
|
$entity_info = entity_get_info('file');
|
132 |
|
|
foreach ($entity_info['bundles'] as $file_type => $file_type_info) {
|
133 |
|
|
|
134 |
|
|
$mode_data_key = $file_type . '_wysiwyg_view_mode';
|
135 |
|
|
if (isset($defaults[$mode_data_key])) {
|
136 |
|
|
$view_mode = $defaults[$mode_data_key];
|
137 |
|
|
db_delete('media_view_mode_wysiwyg')
|
138 |
|
|
->condition('type', $file_type)
|
139 |
|
|
->execute();
|
140 |
|
|
if ($view_mode != 'none') {
|
141 |
|
|
$record = array('type' => $file_type, 'view_mode' => $view_mode);
|
142 |
|
|
drupal_write_record('media_view_mode_wysiwyg', $record);
|
143 |
|
|
}
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
$view_modes = array_keys($entity_info['view modes']);
|
147 |
|
|
array_push($view_modes, 'default');
|
148 |
|
|
foreach ($view_modes as $view_mode) {
|
149 |
|
|
$restrict_data_key = $file_type . '_' . $view_mode . '_restrict_wysiwyg';
|
150 |
|
|
if (isset($defaults[$restrict_data_key])) {
|
151 |
|
|
db_delete('media_restrict_wysiwyg')
|
152 |
|
|
->condition('type', $file_type)
|
153 |
|
|
->condition('display', $view_mode)
|
154 |
|
|
->execute();
|
155 |
|
|
if ($defaults[$restrict_data_key]) {
|
156 |
|
|
$record = array(
|
157 |
|
|
'type' => $file_type,
|
158 |
|
|
'display' => $view_mode);
|
159 |
|
|
drupal_write_record('media_restrict_wysiwyg', $record);
|
160 |
|
|
}
|
161 |
|
|
}
|
162 |
|
|
}
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
/**
|
168 |
|
|
* Implements hook_features_rebuild().
|
169 |
|
|
*/
|
170 |
|
|
function media_wysiwyg_features_rebuild($module) {
|
171 |
|
|
media_wysiwyg_features_revert($module);
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
/**
|
175 |
|
|
* Implements hook_features_enable_feature().
|
176 |
|
|
*/
|
177 |
|
|
function media_wysiwyg_features_enable_feature($module) {
|
178 |
|
|
media_wysiwyg_features_revert($module);
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
/**
|
182 |
|
|
* Retrieve the WYSIWYG view mode for the specified file type.
|
183 |
|
|
*
|
184 |
|
|
* @param string $file_type
|
185 |
|
|
* The machine name of the file type.
|
186 |
|
|
*/
|
187 |
|
|
function _media_wysiwyg_get_wysiwyg_mode($file_type) {
|
188 |
|
|
$view_mode = db_query(
|
189 |
|
|
'SELECT view_mode FROM {media_view_mode_wysiwyg} WHERE type = :type',
|
190 |
|
|
array(':type' => $file_type))
|
191 |
|
|
->fetchField();
|
192 |
|
|
return $view_mode;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
/**
|
196 |
|
|
* Retrieve a list of view modes that should not be available in the WYSIWYG for
|
197 |
|
|
* the specified file type.
|
198 |
|
|
*
|
199 |
|
|
* @param string $file_type
|
200 |
|
|
* The machine name of the file type.
|
201 |
|
|
*/
|
202 |
|
|
function _media_wysiwyg_get_restricted_modes($file_type) {
|
203 |
|
|
$restricted_view_modes = db_query(
|
204 |
|
|
'SELECT display FROM {media_restrict_wysiwyg} WHERE type = :type',
|
205 |
|
|
array(':type' => $file_type))
|
206 |
|
|
->fetchCol();
|
207 |
|
|
return $restricted_view_modes;
|
208 |
|
|
} |