annotate mee.module @ 20:97a888cb817c

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