annotate mee.module @ 14:50a57b1517cb

Fully working MEE, with Ressource Manager & all
author Franck Deroche <franck@defr.org>
date Fri, 18 Sep 2009 15:18:53 +0200
parents 842d89897cb4
children a3d780c2979a
rev   line source
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);
franck@14 27 if(!empty($scald_config->contexts)) {
franck@14 28 foreach ($scald_config->contexts as $context => $details) {
franck@14 29 $theme['mee_formatter_'. $context] = array(
franck@14 30 'arguments' => array('element' => NULL),
franck@14 31 'function' => 'theme_mee_context_formatter',
franck@14 32 );
franck@14 33 }
tom@2 34 }
eads@0 35 return $theme;
eads@0 36 }
eads@0 37
eads@0 38 /**
eads@0 39 * Implementation of hook_field_info().
eads@0 40 */
eads@0 41 function mee_field_info() {
eads@0 42 return array(
eads@0 43 'multimedia_editorial_element' => array(
eads@0 44 'label' => t('Multimedia Editorial Element (MEE)'),
eads@0 45 'description' => t('MEE combines Scald, WYSIWYG, and DnD to create a multimedia enabled text field.'),
eads@0 46 ),
eads@0 47 );
eads@0 48 }
eads@0 49
eads@0 50 /**
eads@0 51 * Implementation of hook_field_settings().
eads@0 52 */
eads@0 53 function mee_field_settings($op, $field) {
eads@0 54 switch ($op) {
eads@0 55 case 'form':
eads@0 56 $form = array();
eads@0 57 $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)'));
tom@5 58
tom@5 59 $scald_config = variable_get('scald_config', 0);
tom@5 60 $context_options = array();
tom@5 61 $contexts_result = db_query("SELECT context, title FROM {scald_contexts} WHERE context IN ('" . implode("', '", array_keys($scald_config->contexts)) . "') ORDER BY title");
tom@5 62 while ($context_raw = db_fetch_array($contexts_result)) {
tom@5 63 $context_options[$context_raw['context']] = $context_raw['title'];
tom@5 64 }
tom@5 65
eads@0 66 $form['mee_processing'] = array(
eads@0 67 '#type' => 'radios',
eads@0 68 '#title' => t('Text processing'),
eads@0 69 '#default_value' => is_numeric($field['mee_processing']) ? $field['mee_processing'] : 1,
eads@0 70 '#options' => $options,
eads@0 71 '#description' => t('Filtered text, with a WYSIWYG editor defined on one or more input formats, is strongly recommended.'),
eads@0 72 );
eads@0 73 // @TODO Ask Drupal about available libraries
eads@0 74 $form['mee_dnd_callback_url'] = array(
eads@0 75 '#type' => 'textfield',
eads@0 76 '#title' => t('Library callback URL'),
eads@0 77 '#default_value' => url($field['mee_dnd_callback_url']) ? $field['mee_dnd_callback_url'] : '',
eads@0 78 '#description' => t('The absolute URL or relative path of a callback URL that provides proper JSON to the drag and drop library.'),
eads@0 79 );
tom@5 80 $form['mee_scald_editor_context'] = array(
tom@5 81 '#type' => 'select',
tom@5 82 '#title' => t('Scald Editor Context'),
tom@5 83 '#description' => t('Choose a Scald Context to use for displaying Scald Atoms included in the textarea during editing.'),
tom@5 84 '#default_value' => $field['mee_scald_editor_context'],
tom@5 85 '#options' => $context_options,
tom@5 86 );
eads@0 87 return $form;
eads@0 88
eads@0 89 case 'save':
tom@4 90 return array('mee_processing', 'mee_dnd_callback_url', 'mee_scald_editor_context');
eads@0 91
eads@0 92 case 'database columns':
eads@0 93 $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE);
franck@13 94 $columns['short'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE);
eads@0 95 $columns['dnd_callback_url'] = array('type' => 'text', 'size' => 'small', 'not null' => FALSE);
eads@0 96 if (!empty($field['mee_processing'])) {
eads@0 97 $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE);
eads@0 98 }
tom@5 99 $columns['mee_scald_editor_context'] = array('type' => 'text', 'size' => 'small', 'not null' => FALSE);
eads@0 100 return $columns;
eads@0 101
eads@0 102 case 'views data':
eads@0 103 return content_views_field_views_data($field);
eads@0 104 }
eads@0 105 }
eads@0 106
eads@0 107 /**
eads@0 108 * Implementation of hook_field().
eads@0 109 */
eads@0 110 function mee_field($op, &$node, $field, &$items, $teaser, $page) {
eads@0 111 switch ($op) {
tom@2 112 case 'presave':
tom@5 113 foreach ($items as $delta => &$item) {
franck@14 114 // Put everything in the ['mee'] namespace back into the array.
franck@14 115 // This let CCK store the value and short fields natively.
franck@14 116 if (is_array($item['mee'])) {
franck@14 117 foreach ($item['mee'] as $k => $v) {
franck@14 118 $items[$delta][$k] = $v;
franck@14 119 }
franck@14 120 }
franck@14 121 if (!empty($item['value']) && variable_get('mee_store_sas', FALSE)) {
franck@14 122 $item['value'] = scald_rendered_to_sas($item['value']);
tom@5 123 }
tom@5 124 }
tom@2 125 break; // end 'submit'
tom@2 126
tom@2 127 case 'insert':
tom@2 128 foreach ($items as $delta => $item) {
franck@13 129 // Process the value and generate an atom
franck@14 130 $sas = scald_rendered_to_sas($item['value']);
franck@14 131 $scald_included = scald_included($sas);
franck@14 132 $sids = array_unique($scald_included);
tom@3 133
tom@3 134 $temp_atom = new stdClass;
tom@3 135 $temp_atom->type = 'composite';
tom@3 136 $temp_atom->provider = 'mee';
tom@3 137 $temp_atom->base_id = $node->nid . ':' . $delta;
tom@3 138 $temp_atom->publisher = $node->uid;
tom@5 139 $temp_atom->title = $node->title . ' - ' . $field['widget']['label'] . ' (#' . $delta . ')';
tom@3 140 $temp_atom->authors = array(scald_uid_to_aid($node->uid));
tom@2 141 $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included);
franck@14 142
tom@2 143 $sid = scald_register_atom($temp_atom);
franck@14 144
franck@13 145 // Ressource manager associations
franck@14 146 if (empty($item['ressource_manager'])) {
franck@14 147 _mee_load_ressources($node, $field, $item);
franck@14 148 }
franck@14 149 $separator = $item['ressource_manager'][0]['weight'];
franck@14 150 foreach ($sids as $sid) {
franck@14 151 $ressource = $item['ressource_manager'][$sid];
franck@14 152 $weight = $ressource['weight'] - $separator;
franck@14 153 $required = $ressource['required'];
franck@14 154 $query = "INSERT into {mee_ressources} (content_nid, atom_sid, field, weight, required) VALUES (%d, %d, '%s', %d, %d)";
franck@14 155 db_query($query, $node->nid, $sid, $field['field_name'], $weight, $required);
franck@13 156 }
tom@2 157 }
tom@2 158 break; // end 'insert'
tom@2 159
tom@2 160 case 'update':
tom@2 161 foreach ($items as $delta => $item) {
franck@13 162 // Process the value
franck@14 163 $sas = scald_rendered_to_sas($item['value']);
franck@14 164 $scald_included = scald_included($sas);
franck@14 165 $sids = array_unique($scald_included);
franck@14 166
franck@14 167 // Update ressources weight
franck@14 168 // In fact, we'll delete all the associations and recreate afterwards
franck@14 169 // the needed one, to be sure that new ressources are correctly
franck@14 170 // registered, and that no longer used one are removed.
franck@14 171 if (!is_array($item['ressource_manager'])) {
franck@14 172 _mee_load_ressources($node, $field, $item);
franck@14 173 }
franck@14 174 db_query("DELETE FROM {mee_ressources} WHERE content_nid=%d AND field='%s'", $node->nid, $field['field_name']);
franck@14 175 // We'll normalize the weight, putting our separator at 0.
franck@14 176 $separator = $item['ressource_manager'][0]['weight'];
franck@14 177 foreach ($sids as $sid) {
franck@14 178 $ressource = $item['ressource_manager'][$sid];
franck@14 179 $required = $ressource['required'];
franck@14 180 $weight = $ressource['weight'] - $separator;
franck@14 181 // insert in the table
franck@14 182 $query = "INSERT into {mee_ressources} (content_nid, atom_sid, field, weight, required) VALUES (%d, %d, '%s', %d, %d)";
franck@14 183 db_query($query, $node->nid, $sid, $field['field_name'], $weight, $required);
franck@14 184 }
tom@2 185
tom@3 186 // @@@TODO: Handle failure of fetch
tom@3 187 $atom = scald_fetch(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE));
tom@3 188 $atom->publisher = $node->uid;
franck@6 189 $atom->title = $node->title;
tom@5 190 $atom->authors = array(scald_uid_to_aid($node->uid)); // @@@TODO: This will completely override any authors listed & replace only with the Publisher.
franck@6 191 $atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included);
tom@3 192
tom@3 193 scald_update_atom($atom);
tom@2 194 }
tom@2 195 break; // end 'update'
tom@2 196
tom@2 197 case 'delete':
tom@3 198 foreach ($items as $delta => $item) {
tom@3 199 scald_unregister_atom(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE));
tom@3 200 }
franck@14 201
franck@14 202 // Delete all ressources associations for this field
franck@14 203 $query = "DELETE FROM {mee_ressources} WHERE content_nid = %d AND field = '%s'";
franck@14 204 db_query($query, $node->nid, $field['field_name']);
tom@2 205 break; // end 'delete'
tom@2 206
eads@0 207 case 'sanitize':
eads@0 208 foreach ($items as $delta => $item) {
eads@0 209 if (!empty($field['mee_processing'])) {
eads@0 210 $check = is_null($node) || (isset($node->build_mode) && $node->build_mode == NODE_BUILD_PREVIEW);
franck@14 211 $text = isset($item['value']) ? check_markup($item['value'], $item['format'], $check) : '';
eads@0 212 }
eads@0 213 else {
franck@14 214 $text = check_plain($item['value']);
eads@0 215 }
eads@0 216 $items[$delta]['safe'] = $text;
eads@0 217 }
tom@2 218 break; // end 'sanitize'
eads@0 219 }
eads@0 220 }
eads@0 221
eads@0 222 /**
eads@0 223 * Implementation of hook_content_is_empty().
eads@0 224 */
eads@0 225 function mee_content_is_empty($item, $field) {
franck@14 226 if (empty($item['value']) && (string)$item['value'] !== '0') {
eads@0 227 return TRUE;
eads@0 228 }
eads@0 229 return FALSE;
eads@0 230 }
eads@0 231
eads@0 232 /**
eads@0 233 * Implementation of hook_field_formatter_info().
eads@0 234 */
eads@0 235 function mee_field_formatter_info() {
eads@0 236 $formatters = array(
eads@0 237 'default' => array(
eads@0 238 'label' => t('Filtered text'),
eads@0 239 'field types' => array('multimedia_editorial_element'),
eads@0 240 'multiple values' => CONTENT_HANDLE_CORE,
eads@0 241 ),
eads@0 242 'plain' => array(
eads@0 243 'label' => t('Plain text'),
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 //@TODO generate context processor based field formatters
eads@0 249 //foreach (scald_contexts() as $context) {
eads@0 250 // $formatters[$context] = array(
eads@0 251 // 'label' => t('Scald context processor: @context', array('@context' => $context),
eads@0 252 // 'field types' => 'mee',
eads@0 253 // );
eads@0 254 //}
eads@0 255 return $formatters;
eads@0 256 }
eads@0 257
eads@0 258 function theme_mee_formatter_default($element) {
franck@14 259 // What's stored is exactly what the user entered, and not the SAS
franck@14 260 // representation. In general, that's that we want to output, *but*
franck@14 261 // we should also check that the atom is still available... And replace
franck@14 262 // it if it isn't.
franck@14 263 if (!variable_get('mee_store_sas', FALSE)) {
franck@14 264 $sas = scald_rendered_to_sas($element['#item']['value']);
franck@14 265 $included = scald_included($sas);
franck@14 266 $altered = FALSE;
franck@14 267 foreach($included as $sid) {
franck@14 268 $atom = scald_fetch($sid);
franck@14 269 if (!scald_action_permitted($atom, 'view')) {
franck@14 270 $altered = TRUE;
franck@14 271 $replace = scald_scald_render($atom, 'no-access');
franck@14 272 $element['#item']['value'] = preg_replace(
franck@14 273 "/<!--(\s*)scald=$sid(.*)END scald=$sid(\s*)-->/sU",
franck@14 274 scald_scald_render($atom, 'no-access'),
franck@14 275 $element['#item']['value']
franck@14 276 );
franck@14 277 }
franck@14 278 }
franck@14 279 if ($altered) {
franck@14 280 $element['#item']['safe'] = check_markup($element['#item']['value']);
franck@14 281 }
franck@14 282 }
tom@4 283 return scald_sas_to_rendered($element['#item']['safe']);
eads@0 284 }
eads@0 285
eads@0 286 /**
eads@0 287 * Theme function for 'plain' text field formatter.
eads@0 288 */
eads@0 289 function theme_mee_formatter_plain($element) {
tom@4 290 return strip_tags(scald_sas_to_rendered($element['#item']['safe'], 'title', TRUE));
eads@0 291 }
eads@0 292
tom@4 293 //function theme_mee_context_formatter($element) {
tom@4 294 // return 'foo';
tom@4 295 //}
eads@0 296
eads@0 297 /**
eads@0 298 * Implementation of hook_widget_info().
eads@0 299 */
eads@0 300 function mee_widget_info() {
eads@0 301 return array(
eads@0 302 'mee_textarea' => array(
eads@0 303 'label' => t('MEE Textarea'),
eads@0 304 'field types' => array('multimedia_editorial_element'),
eads@0 305 'multiple values' => CONTENT_HANDLE_CORE,
eads@0 306 ),
eads@0 307 );
eads@0 308 }
eads@0 309
eads@0 310 /**
eads@0 311 * Implementation of FAPI hook_elements().
eads@0 312 *
eads@0 313 * Any FAPI callbacks needed for individual widgets can be declared here,
eads@0 314 * and the element will be passed to those callbacks for processing.
eads@0 315 *
eads@0 316 * Drupal will automatically theme the element using a theme with
eads@0 317 * the same name as the hook_elements key.
eads@0 318 */
eads@0 319 function mee_elements() {
eads@0 320 return array(
eads@0 321 'mee_textarea' => array(
eads@0 322 '#input' => TRUE,
eads@0 323 '#columns' => array('value', 'format'), '#delta' => 0,
eads@0 324 '#process' => array('mee_textarea_process', 'dnd_process_textarea'),
eads@0 325 '#filter_value' => FILTER_FORMAT_DEFAULT,
eads@0 326 ),
eads@0 327 );
eads@0 328 }
eads@0 329
eads@0 330 /**
eads@0 331 * Implementation of hook_widget_settings().
eads@0 332 */
eads@0 333 function mee_widget_settings($op, $widget) {
eads@0 334 switch ($op) {
eads@0 335 case 'form':
eads@0 336 $form = array();
eads@0 337 $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5;
eads@0 338 $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
eads@0 339 $form['rows'] = array(
eads@0 340 '#type' => 'textfield',
eads@0 341 '#title' => t('Rows'),
eads@0 342 '#default_value' => $rows,
eads@0 343 '#element_validate' => array('_mee_widget_settings_row_validate'),
eads@0 344 '#required' => TRUE,
eads@0 345 );
eads@0 346 $form['size'] = array('#type' => 'hidden', '#value' => $size);
eads@0 347 return $form;
eads@0 348
eads@0 349 case 'save':
eads@0 350 return array('rows', 'size');
eads@0 351 }
eads@0 352 }
eads@0 353
eads@0 354 function _mee_widget_settings_row_validate($element, &$form_state) {
eads@0 355 $value = $form_state['values']['rows'];
eads@0 356 if (!is_numeric($value) || intval($value) != $value || $value <= 0) {
eads@0 357 form_error($element, t('"Rows" must be a positive integer.'));
eads@0 358 }
eads@0 359 }
eads@0 360
eads@0 361 function _mee_widget_settings_size_validate($element, &$form_state) {
eads@0 362 $value = $form_state['values']['size'];
eads@0 363 if (!is_numeric($value) || intval($value) != $value || $value <= 0) {
eads@0 364 form_error($element, t('"Size" must be a positive integer.'));
eads@0 365 }
eads@0 366 }
eads@0 367
eads@0 368 /**
eads@0 369 * Implementation of hook_widget().
eads@0 370 *
eads@0 371 * Attach a single form element to the form. It will be built out and
eads@0 372 * validated in the callback(s) listed in hook_elements. We build it
eads@0 373 * out in the callbacks rather than here in hook_widget so it can be
eads@0 374 * plugged into any module that can provide it with valid
eads@0 375 * $field information.
eads@0 376 *
eads@0 377 * Content module will set the weight, field name and delta values
eads@0 378 * for each form element. This is a change from earlier CCK versions
eads@0 379 * where the widget managed its own multiple values.
eads@0 380 *
eads@0 381 * If there are multiple values for this field, the content module will
eads@0 382 * call this function as many times as needed.
eads@0 383 *
eads@0 384 * @param $form
eads@0 385 * the entire form array, $form['#node'] holds node information
eads@0 386 * @param $form_state
eads@0 387 * the form_state, $form_state['values'][$field['field_name']]
eads@0 388 * holds the field's form values.
eads@0 389 * @param $field
eads@0 390 * the field array
eads@0 391 * @param $items
eads@0 392 * array of default values for this field
eads@0 393 * @param $delta
eads@0 394 * the order of this item in the array of subelements (0, 1, 2, etc)
eads@0 395 *
eads@0 396 * @return
eads@0 397 * the form item for a single element for this field
eads@0 398 */
eads@0 399 function mee_widget(&$form, &$form_state, $field, $items, $delta = 0) {
tom@5 400 if (isset($items[$delta]['value'])) {
tom@5 401 $items[$delta]['value'] = scald_sas_to_rendered($items[$delta]['value'], $field['mee_scald_editor_context'], TRUE);
tom@5 402 }
eads@0 403 $element = array(
eads@0 404 '#type' => $field['widget']['type'],
tom@5 405 '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
eads@0 406 );
tom@5 407
eads@0 408 return $element;
eads@0 409 }
eads@0 410
eads@0 411 /**
eads@0 412 * Process an individual element.
eads@0 413 *
eads@0 414 * Build the form element. When creating a form using FAPI #process,
eads@0 415 * note that $element['#value'] is already set.
eads@0 416 *
eads@0 417 * The $fields array is in $form['#field_info'][$element['#field_name']].
eads@0 418 */
eads@0 419 function mee_textarea_process($element, $edit, $form_state, $form) {
eads@0 420 drupal_add_css(drupal_get_path('module', 'mee') .'/css/mee.css');
franck@8 421 drupal_add_js(drupal_get_path('module', 'mee') .'/mee.js');
franck@11 422 $element['mee'] = array(
franck@11 423 '#type' => 'markup',
franck@11 424 '#prefix' => '<div class="mee-wrap-editor-library">',
franck@11 425 '#suffix' => '</div>',
franck@11 426 );
franck@11 427
eads@0 428 $field = $form['#field_info'][$element['#field_name']];
eads@0 429 $field_key = $element['#columns'][0];
franck@11 430 $element['mee']['ressource_manager'] = array(
franck@14 431 '#type' => 'markup',
franck@11 432 '#weight' => 0.5,
franck@14 433 '#theme' => 'mee_ressource_manager'
franck@11 434 );
franck@14 435
franck@14 436
franck@14 437 if (!isset($element['#value']['mee']['ressource_manager'])) {
franck@14 438 $element['#value']['mee']['ressource_manager'] = array();
franck@14 439 // Restore/Generate the associated ressources in a proper order
franck@14 440 $query = "SELECT * FROM {mee_ressources} WHERE content_nid=%d AND field='%s' ORDER BY weight ASC";
franck@14 441 $result = db_query($query, $form['nid']['#value'], $element['#field_name']);
franck@14 442 while ($item = db_fetch_object($result)) {
franck@14 443 $element['#value']['mee']['ressource_manager'][$item->atom_sid] = (array)$item;
franck@14 444 }
franck@14 445 $element['#value']['mee']['ressource_manager'][0] = array('weight' => 0);
franck@14 446 }
franck@14 447
franck@14 448 foreach($element['#value']['mee']['ressource_manager'] as $sid => $item) {
franck@14 449 $atom = scald_fetch($sid);
franck@14 450 $title = $atom->title;
franck@14 451
franck@14 452 $element['mee']['ressource_manager'][$sid] = array(
franck@14 453 'title' => array(
franck@14 454 '#type' => 'markup',
franck@14 455 '#value' => $title,
franck@14 456 ),
franck@14 457 'required' => array(
franck@14 458 '#type' => 'select',
franck@14 459 '#options' => array(t('Optional'), t('Required')),
franck@14 460 '#default_value' => $item['required']
franck@14 461 ),
franck@14 462 'weight' => array(
franck@14 463 '#type' => 'weight',
franck@14 464 '#default_value' => $item['weight'],
franck@14 465 ),
franck@14 466 '#weight' => $item['weight']
franck@14 467 );
franck@14 468 }
franck@14 469
franck@14 470 // And now we add the separator
franck@11 471 $element['mee']['ressource_manager'][0] = array(
franck@11 472 'title' => array(
franck@11 473 '#type' => 'markup',
franck@14 474 '#value' => t('< Primaire / Secondaire >'),
franck@14 475 ),
franck@14 476 'required' => array(
franck@14 477 '#type' => 'markup',
franck@14 478 '#value' => '-'
franck@11 479 ),
franck@11 480 'weight' => array(
franck@14 481 '#type' => 'weight',
franck@14 482 '#prefix' => '<div class="mee-rm-separator">',
franck@14 483 '#suffix' => '</div>'
franck@14 484 ),
franck@14 485 '#weight' => $element['#value']['mee']['ressource_manager'][0]['weight']
franck@11 486 );
franck@14 487 if ($element['#value'][$field_key]) {
franck@14 488 $element['#value']['mee'][$field_key] = $element['#value'][$field_key];
franck@14 489 }
franck@11 490 $element['mee'][$field_key] = array(
eads@0 491 '#type' => 'textarea',
franck@14 492 '#default_value' => isset($element['#value']['mee'][$field_key]) ? $element['#value']['mee'][$field_key] : NULL,
eads@0 493 '#rows' => !empty($field['widget']['rows']) ? $field['widget']['rows'] : 10,
eads@0 494 '#weight' => 0,
eads@0 495 // The following values were set by the content module and need
eads@0 496 // to be passed down to the nested element.
eads@0 497 '#title' => $element['#title'],
eads@0 498 '#description' => $element['#description'],
eads@0 499 '#required' => $element['#required'],
eads@0 500 '#field_name' => $element['#field_name'],
eads@0 501 '#type_name' => $element['#type_name'],
eads@0 502 '#delta' => $element['#delta'],
eads@0 503 '#columns' => $element['#columns'],
eads@0 504 '#dnd-enabled' => TRUE,
eads@0 505 '#dnd-settings' => array(
eads@0 506 'drop_selector' => '#'. $element['#id'] .' .drop',
eads@0 507 'url' => $field['mee_dnd_callback_url'],
eads@0 508 ),
eads@0 509 );
eads@0 510
eads@0 511 if (!empty($field['mee_processing'])) {
eads@0 512 $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format';
eads@0 513 $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT;
eads@0 514 $parents = array_merge($element['#parents'] , array($filter_key));
franck@11 515 $element['mee'][$filter_key] = filter_form($format, 1, $parents);
franck@11 516 $element['mee'][$filter_key]['#prefix'] = '<div class="mee-filter-form">';
franck@11 517 $element['mee'][$filter_key]['#suffix'] = '</div>';
eads@0 518 }
eads@0 519
eads@0 520 // Used so that hook_field('validate') knows where to flag an error.
eads@0 521 $element['_error_element'] = array(
eads@0 522 '#type' => 'value',
eads@0 523 '#value' => implode('][', array_merge($element['#parents'], array($field_key))),
eads@0 524 );
franck@11 525 $element['mee']['short'] = array(
franck@11 526 '#type' => 'textarea',
franck@11 527 '#title' => 'Contenu court',
franck@11 528 '#rows' => 5,
franck@13 529 '#weight' => 100,
franck@13 530 '#default_value' => $element['#value']['short']
franck@11 531 );
eads@0 532
eads@0 533
eads@0 534 return $element;
eads@0 535 }
eads@0 536
eads@0 537 /**
eads@0 538 * FAPI theme for an individual text elements.
eads@0 539 *
eads@0 540 * The textfield or textarea is already rendered by the
eads@0 541 * textfield or textarea themes and the html output
eads@0 542 * lives in $element['#children']. Override this theme to
eads@0 543 * make custom changes to the output.
eads@0 544 *
eads@0 545 * $element['#field_name'] contains the field name
eads@0 546 * $element['#delta] is the position of this element in the group
eads@0 547 */
eads@0 548 function theme_mee_textarea($element) {
eads@0 549 return $element['#children'];
eads@0 550 }
tom@2 551
franck@11 552 function theme_mee_ressource_manager(&$form) {
franck@11 553 static $count = 0;
franck@11 554 $id = 'mee-ressource-manager-'. $count;
franck@11 555 drupal_add_tabledrag($id, 'order', 'sibling', 'mee-rm-weight');
franck@11 556 $count++;
franck@14 557 $header = array('', t('Title'), t('Required'), t('Weight'));
franck@11 558 $rows = array();
franck@11 559 foreach(element_children($form) as $key) {
franck@11 560 $form[$key]['weight']['#attributes']['class'] = 'mee-rm-weight';
franck@11 561
franck@11 562 $row = array('');
franck@11 563 $row[] = drupal_render($form[$key]['title']);
franck@14 564 $row[] = drupal_render($form[$key]['required']);
franck@11 565 $row[] = drupal_render($form[$key]['weight']);
franck@11 566 $rows[] = array('data' => $row, 'class' => 'draggable');
franck@11 567 }
franck@11 568 $output = theme('table', $header, $rows, array(
franck@11 569 'id' => $id,
franck@11 570 'class' => 'mee-ressource-manager'
franck@12 571 ),
franck@12 572 t('Ressource Manager')
franck@12 573 );
franck@11 574 $output .= drupal_render($form);
franck@11 575 return $output;
franck@11 576 }
tom@2 577
franck@14 578 function _mee_load_ressources($node, $field, &$item) {
franck@14 579 $results = db_query("
franck@14 580 SELECT atom_sid, weight
franck@14 581 FROM {mee_ressources}
franck@14 582 WHERE content_nid=%d AND field='%s'",
franck@14 583 array(
franck@14 584 ':nid' => $node->nid,
franck@14 585 ':field' => $field['field_name']
franck@14 586 )
franck@14 587 );
franck@14 588 $item['ressource_manager'] = array();
franck@14 589 while($r = db_fetch_object($results)) {
franck@14 590 $item['ressource_manager'][$r->atom_sid] = array('weight' => $r->weight);
franck@14 591 }
franck@14 592 $item['ressource_manager'][0] = array('weight' => 0);
franck@14 593 }
tom@2 594
tom@2 595
tom@2 596 /*******************************************************************************
tom@2 597 * SCALD HOOK IMPLEMENTATIONS
tom@2 598 ******************************************************************************/
tom@2 599
tom@2 600 /**
tom@2 601 * Implementation of hook_scald_provider().
tom@2 602 */
tom@2 603 function mee_scald_provider() {
tom@2 604 return array(
tom@2 605 'atoms' => array(
tom@5 606 'composite' => array(
tom@5 607 t('The MEE CCK field.'),
tom@5 608 ),
tom@2 609 ),
tom@2 610 );
tom@2 611 }
tom@2 612
tom@2 613
tom@2 614
tom@2 615 /**
tom@2 616 * Implementation of hook_scald_register_atom().
tom@2 617 */
tom@2 618 function mee_scald_register_atom($atom, $mode) {
tom@2 619
tom@2 620 } // end mee_scald_register_atom()
tom@2 621
tom@2 622
tom@2 623
tom@2 624 /**
tom@2 625 * Implementation of hook_scald_update_atom().
tom@2 626 */
tom@2 627 function mee_scald_update_atom($atom, $mode) {
tom@2 628
tom@2 629 } // end mee_scald_update_atom()
tom@2 630
tom@2 631
tom@2 632
tom@2 633 /**
tom@2 634 * Implementation of hook_scald_unregister_atom().
tom@2 635 */
tom@2 636 function mee_scald_unregister_atom($atom, $mode) {
tom@2 637
tom@2 638 } // end mee_scald_unregister_atom()
tom@2 639
tom@2 640
tom@2 641
tom@2 642 /**
tom@2 643 * Implementation of hook_scald_fetch().
tom@2 644 */
tom@2 645 function mee_scald_fetch(&$atom) {
tom@2 646 $atom->thumbnail_source = drupal_get_path('module', 'scald_composites') . '/assets/thumbnail_composite.png';
tom@2 647 } // end mee_scald_fetch()
tom@2 648
tom@2 649
tom@2 650
tom@2 651 /**
tom@2 652 * Implementation of hook_scald_prerender().
tom@2 653 */
tom@2 654 function mee_scald_prerender(&$atom, $mode) {
tom@2 655
tom@2 656 } // end mee_scald_prerender()
tom@2 657