|
eads@0
|
1 <?php |
|
eads@0
|
2 // $Id; |
|
eads@0
|
3 /** |
|
eads@0
|
4 * @file |
|
eads@0
|
5 * Defines a special textarea, with drag and drop media driven by Scald and |
|
eads@0
|
6 * dnd.module when rich text editing is enabled on the textarea via the |
|
eads@0
|
7 * WYSIWYG API. |
|
eads@0
|
8 */ |
|
eads@0
|
9 |
|
eads@0
|
10 /** |
|
eads@0
|
11 * Implementation of hook_theme(). |
|
eads@0
|
12 */ |
|
eads@0
|
13 function mee_theme() { |
|
eads@0
|
14 $theme = array( |
|
eads@0
|
15 'mee_textarea' => array( |
|
eads@0
|
16 'arguments' => array('element' => NULL), |
|
eads@0
|
17 ), |
|
franck@11
|
18 'mee_ressource_manager' => array( |
|
franck@11
|
19 'arguments' => array('element' => NULL), |
|
franck@11
|
20 ), |
|
eads@0
|
21 'mee_formatter_default' => array( |
|
eads@0
|
22 'arguments' => array('element' => NULL), |
|
eads@0
|
23 ), |
|
eads@0
|
24 ); |
|
tom@2
|
25 |
|
tom@2
|
26 $scald_config = variable_get('scald_config', 0); |
|
tom@2
|
27 foreach ($scald_config->contexts as $context => $details) { |
|
tom@2
|
28 $theme['mee_formatter_'. $context] = array( |
|
tom@2
|
29 'arguments' => array('element' => NULL), |
|
tom@2
|
30 'function' => 'theme_mee_context_formatter', |
|
tom@2
|
31 ); |
|
tom@2
|
32 } |
|
eads@0
|
33 return $theme; |
|
eads@0
|
34 } |
|
eads@0
|
35 |
|
eads@0
|
36 /** |
|
eads@0
|
37 * Implementation of hook_field_info(). |
|
eads@0
|
38 */ |
|
eads@0
|
39 function mee_field_info() { |
|
eads@0
|
40 return array( |
|
eads@0
|
41 'multimedia_editorial_element' => array( |
|
eads@0
|
42 'label' => t('Multimedia Editorial Element (MEE)'), |
|
eads@0
|
43 'description' => t('MEE combines Scald, WYSIWYG, and DnD to create a multimedia enabled text field.'), |
|
eads@0
|
44 ), |
|
eads@0
|
45 ); |
|
eads@0
|
46 } |
|
eads@0
|
47 |
|
eads@0
|
48 /** |
|
eads@0
|
49 * Implementation of hook_field_settings(). |
|
eads@0
|
50 */ |
|
eads@0
|
51 function mee_field_settings($op, $field) { |
|
eads@0
|
52 switch ($op) { |
|
eads@0
|
53 case 'form': |
|
eads@0
|
54 $form = array(); |
|
eads@0
|
55 $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)')); |
|
tom@5
|
56 |
|
tom@5
|
57 $scald_config = variable_get('scald_config', 0); |
|
tom@5
|
58 $context_options = array(); |
|
tom@5
|
59 $contexts_result = db_query("SELECT context, title FROM {scald_contexts} WHERE context IN ('" . implode("', '", array_keys($scald_config->contexts)) . "') ORDER BY title"); |
|
tom@5
|
60 while ($context_raw = db_fetch_array($contexts_result)) { |
|
tom@5
|
61 $context_options[$context_raw['context']] = $context_raw['title']; |
|
tom@5
|
62 } |
|
tom@5
|
63 |
|
eads@0
|
64 $form['mee_processing'] = array( |
|
eads@0
|
65 '#type' => 'radios', |
|
eads@0
|
66 '#title' => t('Text processing'), |
|
eads@0
|
67 '#default_value' => is_numeric($field['mee_processing']) ? $field['mee_processing'] : 1, |
|
eads@0
|
68 '#options' => $options, |
|
eads@0
|
69 '#description' => t('Filtered text, with a WYSIWYG editor defined on one or more input formats, is strongly recommended.'), |
|
eads@0
|
70 ); |
|
eads@0
|
71 // @TODO Ask Drupal about available libraries |
|
eads@0
|
72 $form['mee_dnd_callback_url'] = array( |
|
eads@0
|
73 '#type' => 'textfield', |
|
eads@0
|
74 '#title' => t('Library callback URL'), |
|
eads@0
|
75 '#default_value' => url($field['mee_dnd_callback_url']) ? $field['mee_dnd_callback_url'] : '', |
|
eads@0
|
76 '#description' => t('The absolute URL or relative path of a callback URL that provides proper JSON to the drag and drop library.'), |
|
eads@0
|
77 ); |
|
tom@5
|
78 $form['mee_scald_editor_context'] = array( |
|
tom@5
|
79 '#type' => 'select', |
|
tom@5
|
80 '#title' => t('Scald Editor Context'), |
|
tom@5
|
81 '#description' => t('Choose a Scald Context to use for displaying Scald Atoms included in the textarea during editing.'), |
|
tom@5
|
82 '#default_value' => $field['mee_scald_editor_context'], |
|
tom@5
|
83 '#options' => $context_options, |
|
tom@5
|
84 ); |
|
eads@0
|
85 return $form; |
|
eads@0
|
86 |
|
eads@0
|
87 case 'save': |
|
tom@4
|
88 return array('mee_processing', 'mee_dnd_callback_url', 'mee_scald_editor_context'); |
|
eads@0
|
89 |
|
eads@0
|
90 case 'database columns': |
|
eads@0
|
91 $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE); |
|
franck@13
|
92 $columns['short'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE); |
|
eads@0
|
93 $columns['dnd_callback_url'] = array('type' => 'text', 'size' => 'small', 'not null' => FALSE); |
|
eads@0
|
94 if (!empty($field['mee_processing'])) { |
|
eads@0
|
95 $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE); |
|
eads@0
|
96 } |
|
tom@5
|
97 $columns['mee_scald_editor_context'] = array('type' => 'text', 'size' => 'small', 'not null' => FALSE); |
|
eads@0
|
98 return $columns; |
|
eads@0
|
99 |
|
eads@0
|
100 case 'views data': |
|
eads@0
|
101 return content_views_field_views_data($field); |
|
eads@0
|
102 } |
|
eads@0
|
103 } |
|
eads@0
|
104 |
|
eads@0
|
105 /** |
|
eads@0
|
106 * Implementation of hook_field(). |
|
eads@0
|
107 */ |
|
eads@0
|
108 function mee_field($op, &$node, $field, &$items, $teaser, $page) { |
|
eads@0
|
109 switch ($op) { |
|
tom@2
|
110 case 'presave': |
|
tom@5
|
111 foreach ($items as $delta => &$item) { |
|
franck@13
|
112 if (!empty($item['mee']['value'])) { |
|
franck@13
|
113 $item['mee']['value'] = scald_rendered_to_sas($item['mee']['value']); |
|
tom@5
|
114 } |
|
tom@5
|
115 } |
|
tom@2
|
116 break; // end 'submit' |
|
tom@2
|
117 |
|
tom@2
|
118 case 'insert': |
|
tom@2
|
119 foreach ($items as $delta => $item) { |
|
franck@13
|
120 // Let CCK store the value and short fields |
|
franck@13
|
121 $items[$delta]['value'] = $item['mee']['value']; |
|
franck@13
|
122 $items[$delta]['short'] = $item['mee']['short']; |
|
franck@13
|
123 // Process the value and generate an atom |
|
franck@13
|
124 $scald_included = scald_included($item['mee']['value']); |
|
tom@3
|
125 |
|
tom@3
|
126 $temp_atom = new stdClass; |
|
tom@3
|
127 $temp_atom->type = 'composite'; |
|
tom@3
|
128 $temp_atom->provider = 'mee'; |
|
tom@3
|
129 $temp_atom->base_id = $node->nid . ':' . $delta; |
|
tom@3
|
130 $temp_atom->publisher = $node->uid; |
|
tom@5
|
131 $temp_atom->title = $node->title . ' - ' . $field['widget']['label'] . ' (#' . $delta . ')'; |
|
tom@3
|
132 $temp_atom->authors = array(scald_uid_to_aid($node->uid)); |
|
tom@2
|
133 $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included); |
|
tom@3
|
134 |
|
tom@2
|
135 $sid = scald_register_atom($temp_atom); |
|
franck@13
|
136 // Short content |
|
franck@13
|
137 $short = $item['mee']['short']; |
|
franck@13
|
138 // TODO: Store the short content value |
|
franck@13
|
139 // Ressource manager associations |
|
franck@13
|
140 foreach ($item['mee']['ressource_manager'] as $sid => $ressource) { |
|
franck@13
|
141 // TODO: Store the assocation |
|
franck@13
|
142 } |
|
tom@2
|
143 } |
|
tom@2
|
144 break; // end 'insert' |
|
tom@2
|
145 |
|
tom@2
|
146 case 'update': |
|
tom@2
|
147 foreach ($items as $delta => $item) { |
|
franck@13
|
148 // Let CCK store the value and short fields |
|
franck@13
|
149 $items[$delta]['value'] = $item['mee']['value']; |
|
franck@13
|
150 $items[$delta]['short'] = $item['mee']['short']; |
|
franck@13
|
151 // Process the value |
|
franck@13
|
152 $scald_included = scald_included($item['mee']['value']); |
|
tom@2
|
153 |
|
tom@3
|
154 // @@@TODO: Handle failure of fetch |
|
tom@3
|
155 $atom = scald_fetch(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE)); |
|
tom@3
|
156 $atom->publisher = $node->uid; |
|
franck@6
|
157 $atom->title = $node->title; |
|
tom@5
|
158 $atom->authors = array(scald_uid_to_aid($node->uid)); // @@@TODO: This will completely override any authors listed & replace only with the Publisher. |
|
franck@6
|
159 $atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included); |
|
tom@3
|
160 |
|
tom@3
|
161 scald_update_atom($atom); |
|
tom@2
|
162 } |
|
tom@2
|
163 break; // end 'update' |
|
tom@2
|
164 |
|
tom@2
|
165 case 'delete': |
|
tom@3
|
166 foreach ($items as $delta => $item) { |
|
tom@3
|
167 scald_unregister_atom(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE)); |
|
tom@3
|
168 } |
|
tom@2
|
169 break; // end 'delete' |
|
tom@2
|
170 |
|
eads@0
|
171 case 'sanitize': |
|
eads@0
|
172 foreach ($items as $delta => $item) { |
|
eads@0
|
173 if (!empty($field['mee_processing'])) { |
|
eads@0
|
174 $check = is_null($node) || (isset($node->build_mode) && $node->build_mode == NODE_BUILD_PREVIEW); |
|
franck@13
|
175 $text = isset($item['mee']['value']) ? check_markup($item['mee']['value'], $item['format'], $check) : ''; |
|
eads@0
|
176 } |
|
eads@0
|
177 else { |
|
franck@13
|
178 $text = check_plain($item['mee']['value']); |
|
eads@0
|
179 } |
|
eads@0
|
180 $items[$delta]['safe'] = $text; |
|
eads@0
|
181 } |
|
tom@2
|
182 break; // end 'sanitize' |
|
eads@0
|
183 } |
|
eads@0
|
184 } |
|
eads@0
|
185 |
|
eads@0
|
186 /** |
|
eads@0
|
187 * Implementation of hook_content_is_empty(). |
|
eads@0
|
188 */ |
|
eads@0
|
189 function mee_content_is_empty($item, $field) { |
|
franck@13
|
190 if (empty($item['mee']['value']) && (string)$item['mee']['value'] !== '0') { |
|
eads@0
|
191 return TRUE; |
|
eads@0
|
192 } |
|
eads@0
|
193 return FALSE; |
|
eads@0
|
194 } |
|
eads@0
|
195 |
|
eads@0
|
196 /** |
|
eads@0
|
197 * Implementation of hook_field_formatter_info(). |
|
eads@0
|
198 */ |
|
eads@0
|
199 function mee_field_formatter_info() { |
|
eads@0
|
200 $formatters = array( |
|
eads@0
|
201 'default' => array( |
|
eads@0
|
202 'label' => t('Filtered text'), |
|
eads@0
|
203 'field types' => array('multimedia_editorial_element'), |
|
eads@0
|
204 'multiple values' => CONTENT_HANDLE_CORE, |
|
eads@0
|
205 ), |
|
eads@0
|
206 'plain' => array( |
|
eads@0
|
207 'label' => t('Plain text'), |
|
eads@0
|
208 'field types' => array('multimedia_editorial_element'), |
|
eads@0
|
209 'multiple values' => CONTENT_HANDLE_CORE, |
|
eads@0
|
210 ), |
|
eads@0
|
211 ); |
|
eads@0
|
212 //@TODO generate context processor based field formatters |
|
eads@0
|
213 //foreach (scald_contexts() as $context) { |
|
eads@0
|
214 // $formatters[$context] = array( |
|
eads@0
|
215 // 'label' => t('Scald context processor: @context', array('@context' => $context), |
|
eads@0
|
216 // 'field types' => 'mee', |
|
eads@0
|
217 // ); |
|
eads@0
|
218 //} |
|
eads@0
|
219 return $formatters; |
|
eads@0
|
220 } |
|
eads@0
|
221 |
|
eads@0
|
222 function theme_mee_formatter_default($element) { |
|
tom@4
|
223 return scald_sas_to_rendered($element['#item']['safe']); |
|
eads@0
|
224 } |
|
eads@0
|
225 |
|
eads@0
|
226 /** |
|
eads@0
|
227 * Theme function for 'plain' text field formatter. |
|
eads@0
|
228 */ |
|
eads@0
|
229 function theme_mee_formatter_plain($element) { |
|
tom@4
|
230 return strip_tags(scald_sas_to_rendered($element['#item']['safe'], 'title', TRUE)); |
|
eads@0
|
231 } |
|
eads@0
|
232 |
|
tom@4
|
233 //function theme_mee_context_formatter($element) { |
|
tom@4
|
234 // return 'foo'; |
|
tom@4
|
235 //} |
|
eads@0
|
236 |
|
eads@0
|
237 /** |
|
eads@0
|
238 * Implementation of hook_widget_info(). |
|
eads@0
|
239 */ |
|
eads@0
|
240 function mee_widget_info() { |
|
eads@0
|
241 return array( |
|
eads@0
|
242 'mee_textarea' => array( |
|
eads@0
|
243 'label' => t('MEE Textarea'), |
|
eads@0
|
244 'field types' => array('multimedia_editorial_element'), |
|
eads@0
|
245 'multiple values' => CONTENT_HANDLE_CORE, |
|
eads@0
|
246 ), |
|
eads@0
|
247 ); |
|
eads@0
|
248 } |
|
eads@0
|
249 |
|
eads@0
|
250 /** |
|
eads@0
|
251 * Implementation of FAPI hook_elements(). |
|
eads@0
|
252 * |
|
eads@0
|
253 * Any FAPI callbacks needed for individual widgets can be declared here, |
|
eads@0
|
254 * and the element will be passed to those callbacks for processing. |
|
eads@0
|
255 * |
|
eads@0
|
256 * Drupal will automatically theme the element using a theme with |
|
eads@0
|
257 * the same name as the hook_elements key. |
|
eads@0
|
258 */ |
|
eads@0
|
259 function mee_elements() { |
|
eads@0
|
260 return array( |
|
eads@0
|
261 'mee_textarea' => array( |
|
eads@0
|
262 '#input' => TRUE, |
|
eads@0
|
263 '#columns' => array('value', 'format'), '#delta' => 0, |
|
eads@0
|
264 '#process' => array('mee_textarea_process', 'dnd_process_textarea'), |
|
eads@0
|
265 '#filter_value' => FILTER_FORMAT_DEFAULT, |
|
eads@0
|
266 ), |
|
eads@0
|
267 ); |
|
eads@0
|
268 } |
|
eads@0
|
269 |
|
eads@0
|
270 /** |
|
eads@0
|
271 * Implementation of hook_widget_settings(). |
|
eads@0
|
272 */ |
|
eads@0
|
273 function mee_widget_settings($op, $widget) { |
|
eads@0
|
274 switch ($op) { |
|
eads@0
|
275 case 'form': |
|
eads@0
|
276 $form = array(); |
|
eads@0
|
277 $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5; |
|
eads@0
|
278 $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60; |
|
eads@0
|
279 $form['rows'] = array( |
|
eads@0
|
280 '#type' => 'textfield', |
|
eads@0
|
281 '#title' => t('Rows'), |
|
eads@0
|
282 '#default_value' => $rows, |
|
eads@0
|
283 '#element_validate' => array('_mee_widget_settings_row_validate'), |
|
eads@0
|
284 '#required' => TRUE, |
|
eads@0
|
285 ); |
|
eads@0
|
286 $form['size'] = array('#type' => 'hidden', '#value' => $size); |
|
eads@0
|
287 return $form; |
|
eads@0
|
288 |
|
eads@0
|
289 case 'save': |
|
eads@0
|
290 return array('rows', 'size'); |
|
eads@0
|
291 } |
|
eads@0
|
292 } |
|
eads@0
|
293 |
|
eads@0
|
294 function _mee_widget_settings_row_validate($element, &$form_state) { |
|
eads@0
|
295 $value = $form_state['values']['rows']; |
|
eads@0
|
296 if (!is_numeric($value) || intval($value) != $value || $value <= 0) { |
|
eads@0
|
297 form_error($element, t('"Rows" must be a positive integer.')); |
|
eads@0
|
298 } |
|
eads@0
|
299 } |
|
eads@0
|
300 |
|
eads@0
|
301 function _mee_widget_settings_size_validate($element, &$form_state) { |
|
eads@0
|
302 $value = $form_state['values']['size']; |
|
eads@0
|
303 if (!is_numeric($value) || intval($value) != $value || $value <= 0) { |
|
eads@0
|
304 form_error($element, t('"Size" must be a positive integer.')); |
|
eads@0
|
305 } |
|
eads@0
|
306 } |
|
eads@0
|
307 |
|
eads@0
|
308 /** |
|
eads@0
|
309 * Implementation of hook_widget(). |
|
eads@0
|
310 * |
|
eads@0
|
311 * Attach a single form element to the form. It will be built out and |
|
eads@0
|
312 * validated in the callback(s) listed in hook_elements. We build it |
|
eads@0
|
313 * out in the callbacks rather than here in hook_widget so it can be |
|
eads@0
|
314 * plugged into any module that can provide it with valid |
|
eads@0
|
315 * $field information. |
|
eads@0
|
316 * |
|
eads@0
|
317 * Content module will set the weight, field name and delta values |
|
eads@0
|
318 * for each form element. This is a change from earlier CCK versions |
|
eads@0
|
319 * where the widget managed its own multiple values. |
|
eads@0
|
320 * |
|
eads@0
|
321 * If there are multiple values for this field, the content module will |
|
eads@0
|
322 * call this function as many times as needed. |
|
eads@0
|
323 * |
|
eads@0
|
324 * @param $form |
|
eads@0
|
325 * the entire form array, $form['#node'] holds node information |
|
eads@0
|
326 * @param $form_state |
|
eads@0
|
327 * the form_state, $form_state['values'][$field['field_name']] |
|
eads@0
|
328 * holds the field's form values. |
|
eads@0
|
329 * @param $field |
|
eads@0
|
330 * the field array |
|
eads@0
|
331 * @param $items |
|
eads@0
|
332 * array of default values for this field |
|
eads@0
|
333 * @param $delta |
|
eads@0
|
334 * the order of this item in the array of subelements (0, 1, 2, etc) |
|
eads@0
|
335 * |
|
eads@0
|
336 * @return |
|
eads@0
|
337 * the form item for a single element for this field |
|
eads@0
|
338 */ |
|
eads@0
|
339 function mee_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
|
tom@5
|
340 if (isset($items[$delta]['value'])) { |
|
tom@5
|
341 $items[$delta]['value'] = scald_sas_to_rendered($items[$delta]['value'], $field['mee_scald_editor_context'], TRUE); |
|
tom@5
|
342 } |
|
eads@0
|
343 $element = array( |
|
eads@0
|
344 '#type' => $field['widget']['type'], |
|
tom@5
|
345 '#default_value' => isset($items[$delta]) ? $items[$delta] : '', |
|
eads@0
|
346 ); |
|
tom@5
|
347 |
|
eads@0
|
348 return $element; |
|
eads@0
|
349 } |
|
eads@0
|
350 |
|
eads@0
|
351 /** |
|
eads@0
|
352 * Process an individual element. |
|
eads@0
|
353 * |
|
eads@0
|
354 * Build the form element. When creating a form using FAPI #process, |
|
eads@0
|
355 * note that $element['#value'] is already set. |
|
eads@0
|
356 * |
|
eads@0
|
357 * The $fields array is in $form['#field_info'][$element['#field_name']]. |
|
eads@0
|
358 */ |
|
eads@0
|
359 function mee_textarea_process($element, $edit, $form_state, $form) { |
|
eads@0
|
360 drupal_add_css(drupal_get_path('module', 'mee') .'/css/mee.css'); |
|
franck@8
|
361 drupal_add_js(drupal_get_path('module', 'mee') .'/mee.js'); |
|
eads@0
|
362 |
|
franck@11
|
363 $element['mee'] = array( |
|
franck@11
|
364 '#type' => 'markup', |
|
franck@11
|
365 '#prefix' => '<div class="mee-wrap-editor-library">', |
|
franck@11
|
366 '#suffix' => '</div>', |
|
franck@11
|
367 ); |
|
franck@11
|
368 |
|
eads@0
|
369 $field = $form['#field_info'][$element['#field_name']]; |
|
eads@0
|
370 $field_key = $element['#columns'][0]; |
|
franck@11
|
371 $element['mee']['ressource_manager'] = array( |
|
franck@11
|
372 '#type' => 'markup', |
|
franck@11
|
373 '#weight' => 0.5, |
|
franck@11
|
374 '#theme' => 'mee_ressource_manager' |
|
franck@11
|
375 ); |
|
franck@11
|
376 $element['mee']['ressource_manager'][0] = array( |
|
franck@11
|
377 'title' => array( |
|
franck@11
|
378 '#type' => 'markup', |
|
franck@11
|
379 '#value' => 'Lorem ipsum' |
|
franck@11
|
380 ), |
|
franck@11
|
381 'weight' => array( |
|
franck@11
|
382 '#type' => 'weight', |
|
franck@11
|
383 ) |
|
franck@11
|
384 ); |
|
franck@11
|
385 $element['mee'][$field_key] = array( |
|
eads@0
|
386 '#type' => 'textarea', |
|
eads@0
|
387 '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL, |
|
eads@0
|
388 '#rows' => !empty($field['widget']['rows']) ? $field['widget']['rows'] : 10, |
|
eads@0
|
389 '#weight' => 0, |
|
eads@0
|
390 // The following values were set by the content module and need |
|
eads@0
|
391 // to be passed down to the nested element. |
|
eads@0
|
392 '#title' => $element['#title'], |
|
eads@0
|
393 '#description' => $element['#description'], |
|
eads@0
|
394 '#required' => $element['#required'], |
|
eads@0
|
395 '#field_name' => $element['#field_name'], |
|
eads@0
|
396 '#type_name' => $element['#type_name'], |
|
eads@0
|
397 '#delta' => $element['#delta'], |
|
eads@0
|
398 '#columns' => $element['#columns'], |
|
eads@0
|
399 '#dnd-enabled' => TRUE, |
|
eads@0
|
400 '#dnd-settings' => array( |
|
eads@0
|
401 'drop_selector' => '#'. $element['#id'] .' .drop', |
|
eads@0
|
402 'url' => $field['mee_dnd_callback_url'], |
|
eads@0
|
403 ), |
|
eads@0
|
404 ); |
|
eads@0
|
405 |
|
eads@0
|
406 if (!empty($field['mee_processing'])) { |
|
eads@0
|
407 $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format'; |
|
eads@0
|
408 $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT; |
|
eads@0
|
409 $parents = array_merge($element['#parents'] , array($filter_key)); |
|
franck@11
|
410 $element['mee'][$filter_key] = filter_form($format, 1, $parents); |
|
franck@11
|
411 $element['mee'][$filter_key]['#prefix'] = '<div class="mee-filter-form">'; |
|
franck@11
|
412 $element['mee'][$filter_key]['#suffix'] = '</div>'; |
|
eads@0
|
413 } |
|
eads@0
|
414 |
|
eads@0
|
415 // Used so that hook_field('validate') knows where to flag an error. |
|
eads@0
|
416 $element['_error_element'] = array( |
|
eads@0
|
417 '#type' => 'value', |
|
eads@0
|
418 '#value' => implode('][', array_merge($element['#parents'], array($field_key))), |
|
eads@0
|
419 ); |
|
franck@11
|
420 $element['mee']['short'] = array( |
|
franck@11
|
421 '#type' => 'textarea', |
|
franck@11
|
422 '#title' => 'Contenu court', |
|
franck@11
|
423 '#rows' => 5, |
|
franck@13
|
424 '#weight' => 100, |
|
franck@13
|
425 '#default_value' => $element['#value']['short'] |
|
franck@11
|
426 ); |
|
eads@0
|
427 |
|
eads@0
|
428 |
|
eads@0
|
429 return $element; |
|
eads@0
|
430 } |
|
eads@0
|
431 |
|
eads@0
|
432 /** |
|
eads@0
|
433 * FAPI theme for an individual text elements. |
|
eads@0
|
434 * |
|
eads@0
|
435 * The textfield or textarea is already rendered by the |
|
eads@0
|
436 * textfield or textarea themes and the html output |
|
eads@0
|
437 * lives in $element['#children']. Override this theme to |
|
eads@0
|
438 * make custom changes to the output. |
|
eads@0
|
439 * |
|
eads@0
|
440 * $element['#field_name'] contains the field name |
|
eads@0
|
441 * $element['#delta] is the position of this element in the group |
|
eads@0
|
442 */ |
|
eads@0
|
443 function theme_mee_textarea($element) { |
|
eads@0
|
444 return $element['#children']; |
|
eads@0
|
445 } |
|
tom@2
|
446 |
|
franck@11
|
447 function theme_mee_ressource_manager(&$form) { |
|
franck@11
|
448 static $count = 0; |
|
franck@11
|
449 $id = 'mee-ressource-manager-'. $count; |
|
franck@11
|
450 drupal_add_tabledrag($id, 'order', 'sibling', 'mee-rm-weight'); |
|
franck@11
|
451 $count++; |
|
franck@11
|
452 $header = array('', t('Title'), t('Weight')); |
|
franck@11
|
453 $rows = array(); |
|
franck@11
|
454 foreach(element_children($form) as $key) { |
|
franck@11
|
455 $form[$key]['weight']['#attributes']['class'] = 'mee-rm-weight'; |
|
franck@11
|
456 |
|
franck@11
|
457 $row = array(''); |
|
franck@11
|
458 $row[] = drupal_render($form[$key]['title']); |
|
franck@11
|
459 $row[] = drupal_render($form[$key]['weight']); |
|
franck@11
|
460 $rows[] = array('data' => $row, 'class' => 'draggable'); |
|
franck@11
|
461 } |
|
franck@11
|
462 $output = theme('table', $header, $rows, array( |
|
franck@11
|
463 'id' => $id, |
|
franck@11
|
464 'class' => 'mee-ressource-manager' |
|
franck@12
|
465 ), |
|
franck@12
|
466 t('Ressource Manager') |
|
franck@12
|
467 ); |
|
franck@11
|
468 $output .= drupal_render($form); |
|
franck@11
|
469 return $output; |
|
franck@11
|
470 } |
|
tom@2
|
471 |
|
tom@2
|
472 |
|
tom@2
|
473 |
|
tom@2
|
474 |
|
tom@2
|
475 |
|
tom@2
|
476 /******************************************************************************* |
|
tom@2
|
477 * SCALD HOOK IMPLEMENTATIONS |
|
tom@2
|
478 ******************************************************************************/ |
|
tom@2
|
479 |
|
tom@2
|
480 /** |
|
tom@2
|
481 * Implementation of hook_scald_provider(). |
|
tom@2
|
482 */ |
|
tom@2
|
483 function mee_scald_provider() { |
|
tom@2
|
484 return array( |
|
tom@2
|
485 'atoms' => array( |
|
tom@5
|
486 'composite' => array( |
|
tom@5
|
487 t('The MEE CCK field.'), |
|
tom@5
|
488 ), |
|
tom@2
|
489 ), |
|
tom@2
|
490 ); |
|
tom@2
|
491 } |
|
tom@2
|
492 |
|
tom@2
|
493 |
|
tom@2
|
494 |
|
tom@2
|
495 /** |
|
tom@2
|
496 * Implementation of hook_scald_register_atom(). |
|
tom@2
|
497 */ |
|
tom@2
|
498 function mee_scald_register_atom($atom, $mode) { |
|
tom@2
|
499 |
|
tom@2
|
500 } // end mee_scald_register_atom() |
|
tom@2
|
501 |
|
tom@2
|
502 |
|
tom@2
|
503 |
|
tom@2
|
504 /** |
|
tom@2
|
505 * Implementation of hook_scald_update_atom(). |
|
tom@2
|
506 */ |
|
tom@2
|
507 function mee_scald_update_atom($atom, $mode) { |
|
tom@2
|
508 |
|
tom@2
|
509 } // end mee_scald_update_atom() |
|
tom@2
|
510 |
|
tom@2
|
511 |
|
tom@2
|
512 |
|
tom@2
|
513 /** |
|
tom@2
|
514 * Implementation of hook_scald_unregister_atom(). |
|
tom@2
|
515 */ |
|
tom@2
|
516 function mee_scald_unregister_atom($atom, $mode) { |
|
tom@2
|
517 |
|
tom@2
|
518 } // end mee_scald_unregister_atom() |
|
tom@2
|
519 |
|
tom@2
|
520 |
|
tom@2
|
521 |
|
tom@2
|
522 /** |
|
tom@2
|
523 * Implementation of hook_scald_fetch(). |
|
tom@2
|
524 */ |
|
tom@2
|
525 function mee_scald_fetch(&$atom) { |
|
tom@2
|
526 $atom->thumbnail_source = drupal_get_path('module', 'scald_composites') . '/assets/thumbnail_composite.png'; |
|
tom@2
|
527 } // end mee_scald_fetch() |
|
tom@2
|
528 |
|
tom@2
|
529 |
|
tom@2
|
530 |
|
tom@2
|
531 /** |
|
tom@2
|
532 * Implementation of hook_scald_prerender(). |
|
tom@2
|
533 */ |
|
tom@2
|
534 function mee_scald_prerender(&$atom, $mode) { |
|
tom@2
|
535 |
|
tom@2
|
536 } // end mee_scald_prerender() |
|
tom@2
|
537 |