annotate mee.module @ 26:e2ddb1e80df0 tip

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