Mercurial > defr > drupal > scald > mee
comparison mee.module @ 5:5df98f90134d
Fleshed out the basics of Scald support. MEE + Scald + DnD + Scald DnD Library will deliver a basic-functioning MEE implementation. CRUD ops for Scald Atoms based on the MEE CCK fields all implemented. Admin options for widgets implemented.
| author | Tom Wolf <tom@chicagotech.org> |
|---|---|
| date | Thu, 30 Apr 2009 15:13:58 -0400 |
| parents | e2bf7cf37972 |
| children | 2ef0d9a3eeba |
comparison
equal
deleted
inserted
replaced
| 4:e2bf7cf37972 | 5:5df98f90134d |
|---|---|
| 48 function mee_field_settings($op, $field) { | 48 function mee_field_settings($op, $field) { |
| 49 switch ($op) { | 49 switch ($op) { |
| 50 case 'form': | 50 case 'form': |
| 51 $form = array(); | 51 $form = array(); |
| 52 $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)')); | 52 $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)')); |
| 53 | |
| 54 $scald_config = variable_get('scald_config', 0); | |
| 55 $context_options = array(); | |
| 56 $contexts_result = db_query("SELECT context, title FROM {scald_contexts} WHERE context IN ('" . implode("', '", array_keys($scald_config->contexts)) . "') ORDER BY title"); | |
| 57 while ($context_raw = db_fetch_array($contexts_result)) { | |
| 58 $context_options[$context_raw['context']] = $context_raw['title']; | |
| 59 } | |
| 60 | |
| 53 $form['mee_processing'] = array( | 61 $form['mee_processing'] = array( |
| 54 '#type' => 'radios', | 62 '#type' => 'radios', |
| 55 '#title' => t('Text processing'), | 63 '#title' => t('Text processing'), |
| 56 '#default_value' => is_numeric($field['mee_processing']) ? $field['mee_processing'] : 1, | 64 '#default_value' => is_numeric($field['mee_processing']) ? $field['mee_processing'] : 1, |
| 57 '#options' => $options, | 65 '#options' => $options, |
| 62 '#type' => 'textfield', | 70 '#type' => 'textfield', |
| 63 '#title' => t('Library callback URL'), | 71 '#title' => t('Library callback URL'), |
| 64 '#default_value' => url($field['mee_dnd_callback_url']) ? $field['mee_dnd_callback_url'] : '', | 72 '#default_value' => url($field['mee_dnd_callback_url']) ? $field['mee_dnd_callback_url'] : '', |
| 65 '#description' => t('The absolute URL or relative path of a callback URL that provides proper JSON to the drag and drop library.'), | 73 '#description' => t('The absolute URL or relative path of a callback URL that provides proper JSON to the drag and drop library.'), |
| 66 ); | 74 ); |
| 67 // @@@TODO: Add an "Editor Context" option on a per-field basis | 75 $form['mee_scald_editor_context'] = array( |
| 68 // @@@TODO: Add a "Display Context" option on a per-field basis (this is an override) | 76 '#type' => 'select', |
| 77 '#title' => t('Scald Editor Context'), | |
| 78 '#description' => t('Choose a Scald Context to use for displaying Scald Atoms included in the textarea during editing.'), | |
| 79 '#default_value' => $field['mee_scald_editor_context'], | |
| 80 '#options' => $context_options, | |
| 81 ); | |
| 69 return $form; | 82 return $form; |
| 70 | 83 |
| 71 case 'save': | 84 case 'save': |
| 72 return array('mee_processing', 'mee_dnd_callback_url', 'mee_scald_editor_context'); | 85 return array('mee_processing', 'mee_dnd_callback_url', 'mee_scald_editor_context'); |
| 73 | 86 |
| 75 $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE); | 88 $columns['value'] = array('type' => 'text', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE); |
| 76 $columns['dnd_callback_url'] = array('type' => 'text', 'size' => 'small', 'not null' => FALSE); | 89 $columns['dnd_callback_url'] = array('type' => 'text', 'size' => 'small', 'not null' => FALSE); |
| 77 if (!empty($field['mee_processing'])) { | 90 if (!empty($field['mee_processing'])) { |
| 78 $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE); | 91 $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE); |
| 79 } | 92 } |
| 93 $columns['mee_scald_editor_context'] = array('type' => 'text', 'size' => 'small', 'not null' => FALSE); | |
| 80 return $columns; | 94 return $columns; |
| 81 | 95 |
| 82 case 'views data': | 96 case 'views data': |
| 83 return content_views_field_views_data($field); | 97 return content_views_field_views_data($field); |
| 84 } | 98 } |
| 88 * Implementation of hook_field(). | 102 * Implementation of hook_field(). |
| 89 */ | 103 */ |
| 90 function mee_field($op, &$node, $field, &$items, $teaser, $page) { | 104 function mee_field($op, &$node, $field, &$items, $teaser, $page) { |
| 91 switch ($op) { | 105 switch ($op) { |
| 92 case 'presave': | 106 case 'presave': |
| 93 // @@@TODO: parse the field & replace editor reps with SAS | 107 foreach ($items as $delta => &$item) { |
| 108 if (!empty($item['value'])) { | |
| 109 $item['value'] = scald_rendered_to_sas($item['value']); | |
| 110 } | |
| 111 } | |
| 94 break; // end 'submit' | 112 break; // end 'submit' |
| 95 | 113 |
| 96 case 'insert': | 114 case 'insert': |
| 97 foreach ($items as $delta => $item) { | 115 foreach ($items as $delta => $item) { |
| 98 $scald_included = scald_included($item); | 116 $scald_included = scald_included($item['value']); |
| 99 | 117 |
| 100 $temp_atom = new stdClass; | 118 $temp_atom = new stdClass; |
| 101 $temp_atom->type = 'composite'; | 119 $temp_atom->type = 'composite'; |
| 102 $temp_atom->provider = 'mee'; | 120 $temp_atom->provider = 'mee'; |
| 103 $temp_atom->base_id = $node->nid . ':' . $delta; | 121 $temp_atom->base_id = $node->nid . ':' . $delta; |
| 104 $temp_atom->publisher = $node->uid; | 122 $temp_atom->publisher = $node->uid; |
| 105 $temp_atom->title = $node->title; | 123 $temp_atom->title = $node->title . ' - ' . $field['widget']['label'] . ' (#' . $delta . ')'; |
| 106 $temp_atom->authors = array(scald_uid_to_aid($node->uid)); | 124 $temp_atom->authors = array(scald_uid_to_aid($node->uid)); |
| 107 $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included); | 125 $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included); |
| 108 | 126 |
| 109 $sid = scald_register_atom($temp_atom); | 127 $sid = scald_register_atom($temp_atom); |
| 110 } | 128 } |
| 111 break; // end 'insert' | 129 break; // end 'insert' |
| 112 | 130 |
| 113 case 'update': | 131 case 'update': |
| 114 foreach ($items as $delta => $item) { | 132 foreach ($items as $delta => $item) { |
| 115 $scald_included = scald_included($item); | 133 $scald_included = scald_included($item['value']); |
| 116 | 134 |
| 117 // @@@TODO: Handle failure of fetch | 135 // @@@TODO: Handle failure of fetch |
| 118 $atom = scald_fetch(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE)); | 136 $atom = scald_fetch(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE)); |
| 119 $atom->publisher = $node->uid; | 137 $atom->publisher = $node->uid; |
| 120 $atom->title = $node->title; | 138 $temp_atom->title = $node->title . ' - ' . $field['widget']['label'] . ' (#' . $delta . ')'; |
| 121 $atom->authors = array( | 139 $atom->authors = array(scald_uid_to_aid($node->uid)); // @@@TODO: This will completely override any authors listed & replace only with the Publisher. |
| 122 $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included); | 140 $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included); |
| 123 | 141 |
| 124 scald_update_atom($atom); | 142 scald_update_atom($atom); |
| 125 } | 143 } |
| 126 break; // end 'update' | 144 break; // end 'update' |
| 298 * | 316 * |
| 299 * @return | 317 * @return |
| 300 * the form item for a single element for this field | 318 * the form item for a single element for this field |
| 301 */ | 319 */ |
| 302 function mee_widget(&$form, &$form_state, $field, $items, $delta = 0) { | 320 function mee_widget(&$form, &$form_state, $field, $items, $delta = 0) { |
| 321 if (isset($items[$delta]['value'])) { | |
| 322 $items[$delta]['value'] = scald_sas_to_rendered($items[$delta]['value'], $field['mee_scald_editor_context'], TRUE); | |
| 323 } | |
| 303 $element = array( | 324 $element = array( |
| 304 '#type' => $field['widget']['type'], | 325 '#type' => $field['widget']['type'], |
| 305 '#default_value' => isset($items[$delta]) ? scald_sas_to_rendered($items[$delta], $field['mee_scald_editor_context'], TRUE) : '', | 326 '#default_value' => isset($items[$delta]) ? $items[$delta] : '', |
| 306 ); | 327 ); |
| 328 | |
| 307 return $element; | 329 return $element; |
| 308 } | 330 } |
| 309 | 331 |
| 310 /** | 332 /** |
| 311 * Process an individual element. | 333 * Process an individual element. |
| 388 * Implementation of hook_scald_provider(). | 410 * Implementation of hook_scald_provider(). |
| 389 */ | 411 */ |
| 390 function mee_scald_provider() { | 412 function mee_scald_provider() { |
| 391 return array( | 413 return array( |
| 392 'atoms' => array( | 414 'atoms' => array( |
| 393 'composite' => t('The MEE CCK field.'), | 415 'composite' => array( |
| 416 t('The MEE CCK field.'), | |
| 417 ), | |
| 394 ), | 418 ), |
| 395 ); | 419 ); |
| 396 } | 420 } |
| 397 | 421 |
| 398 | 422 |
| 426 | 450 |
| 427 /** | 451 /** |
| 428 * Implementation of hook_scald_fetch(). | 452 * Implementation of hook_scald_fetch(). |
| 429 */ | 453 */ |
| 430 function mee_scald_fetch(&$atom) { | 454 function mee_scald_fetch(&$atom) { |
| 431 list($nid, $delta) = split(':', $atom->base_id); | |
| 432 $node = node_load($nid); | |
| 433 $atom->title = $node->title . '(' . $delta . ')'; | |
| 434 $atom->description = $atom->title; // @@@TODO: Maybe make this a better description? | |
| 435 $atom->thumbnail_source = drupal_get_path('module', 'scald_composites') . '/assets/thumbnail_composite.png'; | 455 $atom->thumbnail_source = drupal_get_path('module', 'scald_composites') . '/assets/thumbnail_composite.png'; |
| 436 } // end mee_scald_fetch() | 456 } // end mee_scald_fetch() |
| 437 | 457 |
| 438 | 458 |
| 439 | 459 |
