Mercurial > defr > drupal > scald > mee
diff 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 |
line wrap: on
line diff
--- a/mee.module Thu Apr 23 00:04:10 2009 -0500 +++ b/mee.module Thu Apr 30 15:13:58 2009 -0400 @@ -50,6 +50,14 @@ case 'form': $form = array(); $options = array(0 => t('Plain text'), 1 => t('Filtered text (user selects input format)')); + + $scald_config = variable_get('scald_config', 0); + $context_options = array(); + $contexts_result = db_query("SELECT context, title FROM {scald_contexts} WHERE context IN ('" . implode("', '", array_keys($scald_config->contexts)) . "') ORDER BY title"); + while ($context_raw = db_fetch_array($contexts_result)) { + $context_options[$context_raw['context']] = $context_raw['title']; + } + $form['mee_processing'] = array( '#type' => 'radios', '#title' => t('Text processing'), @@ -64,8 +72,13 @@ '#default_value' => url($field['mee_dnd_callback_url']) ? $field['mee_dnd_callback_url'] : '', '#description' => t('The absolute URL or relative path of a callback URL that provides proper JSON to the drag and drop library.'), ); - // @@@TODO: Add an "Editor Context" option on a per-field basis - // @@@TODO: Add a "Display Context" option on a per-field basis (this is an override) + $form['mee_scald_editor_context'] = array( + '#type' => 'select', + '#title' => t('Scald Editor Context'), + '#description' => t('Choose a Scald Context to use for displaying Scald Atoms included in the textarea during editing.'), + '#default_value' => $field['mee_scald_editor_context'], + '#options' => $context_options, + ); return $form; case 'save': @@ -77,6 +90,7 @@ if (!empty($field['mee_processing'])) { $columns['format'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE); } + $columns['mee_scald_editor_context'] = array('type' => 'text', 'size' => 'small', 'not null' => FALSE); return $columns; case 'views data': @@ -90,19 +104,23 @@ function mee_field($op, &$node, $field, &$items, $teaser, $page) { switch ($op) { case 'presave': - // @@@TODO: parse the field & replace editor reps with SAS + foreach ($items as $delta => &$item) { + if (!empty($item['value'])) { + $item['value'] = scald_rendered_to_sas($item['value']); + } + } break; // end 'submit' case 'insert': foreach ($items as $delta => $item) { - $scald_included = scald_included($item); + $scald_included = scald_included($item['value']); $temp_atom = new stdClass; $temp_atom->type = 'composite'; $temp_atom->provider = 'mee'; $temp_atom->base_id = $node->nid . ':' . $delta; $temp_atom->publisher = $node->uid; - $temp_atom->title = $node->title; + $temp_atom->title = $node->title . ' - ' . $field['widget']['label'] . ' (#' . $delta . ')'; $temp_atom->authors = array(scald_uid_to_aid($node->uid)); $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included); @@ -112,13 +130,13 @@ case 'update': foreach ($items as $delta => $item) { - $scald_included = scald_included($item); + $scald_included = scald_included($item['value']); // @@@TODO: Handle failure of fetch $atom = scald_fetch(scald_search(array('base_id' => $node->nid . ':' . $delta), FALSE, TRUE)); $atom->publisher = $node->uid; - $atom->title = $node->title; - $atom->authors = array( + $temp_atom->title = $node->title . ' - ' . $field['widget']['label'] . ' (#' . $delta . ')'; + $atom->authors = array(scald_uid_to_aid($node->uid)); // @@@TODO: This will completely override any authors listed & replace only with the Publisher. $temp_atom->relationships = empty($scald_included) ? array() : array('includes' => $scald_included); scald_update_atom($atom); @@ -300,10 +318,14 @@ * the form item for a single element for this field */ function mee_widget(&$form, &$form_state, $field, $items, $delta = 0) { + if (isset($items[$delta]['value'])) { + $items[$delta]['value'] = scald_sas_to_rendered($items[$delta]['value'], $field['mee_scald_editor_context'], TRUE); + } $element = array( '#type' => $field['widget']['type'], - '#default_value' => isset($items[$delta]) ? scald_sas_to_rendered($items[$delta], $field['mee_scald_editor_context'], TRUE) : '', + '#default_value' => isset($items[$delta]) ? $items[$delta] : '', ); + return $element; } @@ -390,7 +412,9 @@ function mee_scald_provider() { return array( 'atoms' => array( - 'composite' => t('The MEE CCK field.'), + 'composite' => array( + t('The MEE CCK field.'), + ), ), ); } @@ -428,10 +452,6 @@ * Implementation of hook_scald_fetch(). */ function mee_scald_fetch(&$atom) { - list($nid, $delta) = split(':', $atom->base_id); - $node = node_load($nid); - $atom->title = $node->title . '(' . $delta . ')'; - $atom->description = $atom->title; // @@@TODO: Maybe make this a better description? $atom->thumbnail_source = drupal_get_path('module', 'scald_composites') . '/assets/thumbnail_composite.png'; } // end mee_scald_fetch()
