annotate mee.module @ 24:32d8c9f818a8

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