annotate mee.module @ 23:7bb9f2f3b104

Fields: Don't put n/a in case short content is empty
author Franck Deroche <defr@ows.fr>
date Tue, 06 Apr 2010 16:01:10 +0000
parents 97a888cb817c
children 32d8c9f818a8
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) {
defr@23 308 $value = $element['#item']['short'];
defr@23 309 return empty($value) ? $value : check_markup($value);
franck@16 310 }
franck@16 311
tom@4 312 //function theme_mee_context_formatter($element) {
tom@4 313 // return 'foo';
tom@4 314 //}
eads@0 315
eads@0 316 /**
eads@0 317 * Implementation of hook_widget_info().
eads@0 318 */
eads@0 319 function mee_widget_info() {
eads@0 320 return array(
eads@0 321 'mee_textarea' => array(
eads@0 322 'label' => t('MEE Textarea'),
eads@0 323 'field types' => array('multimedia_editorial_element'),
eads@0 324 'multiple values' => CONTENT_HANDLE_CORE,
eads@0 325 ),
eads@0 326 );
eads@0 327 }
eads@0 328
eads@0 329 /**
eads@0 330 * Implementation of FAPI hook_elements().
eads@0 331 *
eads@0 332 * Any FAPI callbacks needed for individual widgets can be declared here,
eads@0 333 * and the element will be passed to those callbacks for processing.
eads@0 334 *
eads@0 335 * Drupal will automatically theme the element using a theme with
eads@0 336 * the same name as the hook_elements key.
eads@0 337 */
eads@0 338 function mee_elements() {
eads@0 339 return array(
eads@0 340 'mee_textarea' => array(
eads@0 341 '#input' => TRUE,
eads@0 342 '#columns' => array('value', 'format'), '#delta' => 0,
eads@0 343 '#process' => array('mee_textarea_process', 'dnd_process_textarea'),
eads@0 344 '#filter_value' => FILTER_FORMAT_DEFAULT,
eads@0 345 ),
eads@0 346 );
eads@0 347 }
eads@0 348
eads@0 349 /**
eads@0 350 * Implementation of hook_widget_settings().
eads@0 351 */
eads@0 352 function mee_widget_settings($op, $widget) {
eads@0 353 switch ($op) {
eads@0 354 case 'form':
eads@0 355 $form = array();
eads@0 356 $rows = (isset($widget['rows']) && is_numeric($widget['rows'])) ? $widget['rows'] : 5;
eads@0 357 $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
eads@0 358 $form['rows'] = array(
eads@0 359 '#type' => 'textfield',
eads@0 360 '#title' => t('Rows'),
eads@0 361 '#default_value' => $rows,
eads@0 362 '#element_validate' => array('_mee_widget_settings_row_validate'),
eads@0 363 '#required' => TRUE,
eads@0 364 );
eads@0 365 $form['size'] = array('#type' => 'hidden', '#value' => $size);
eads@0 366 return $form;
eads@0 367
eads@0 368 case 'save':
eads@0 369 return array('rows', 'size');
eads@0 370 }
eads@0 371 }
eads@0 372
eads@0 373 function _mee_widget_settings_row_validate($element, &$form_state) {
eads@0 374 $value = $form_state['values']['rows'];
eads@0 375 if (!is_numeric($value) || intval($value) != $value || $value <= 0) {
eads@0 376 form_error($element, t('"Rows" must be a positive integer.'));
eads@0 377 }
eads@0 378 }
eads@0 379
eads@0 380 function _mee_widget_settings_size_validate($element, &$form_state) {
eads@0 381 $value = $form_state['values']['size'];
eads@0 382 if (!is_numeric($value) || intval($value) != $value || $value <= 0) {
eads@0 383 form_error($element, t('"Size" must be a positive integer.'));
eads@0 384 }
eads@0 385 }
eads@0 386
eads@0 387 /**
eads@0 388 * Implementation of hook_widget().
eads@0 389 *
eads@0 390 * Attach a single form element to the form. It will be built out and
eads@0 391 * validated in the callback(s) listed in hook_elements. We build it
eads@0 392 * out in the callbacks rather than here in hook_widget so it can be
eads@0 393 * plugged into any module that can provide it with valid
eads@0 394 * $field information.
eads@0 395 *
eads@0 396 * Content module will set the weight, field name and delta values
eads@0 397 * for each form element. This is a change from earlier CCK versions
eads@0 398 * where the widget managed its own multiple values.
eads@0 399 *
eads@0 400 * If there are multiple values for this field, the content module will
eads@0 401 * call this function as many times as needed.
eads@0 402 *
eads@0 403 * @param $form
eads@0 404 * the entire form array, $form['#node'] holds node information
eads@0 405 * @param $form_state
eads@0 406 * the form_state, $form_state['values'][$field['field_name']]
eads@0 407 * holds the field's form values.
eads@0 408 * @param $field
eads@0 409 * the field array
eads@0 410 * @param $items
eads@0 411 * array of default values for this field
eads@0 412 * @param $delta
eads@0 413 * the order of this item in the array of subelements (0, 1, 2, etc)
eads@0 414 *
eads@0 415 * @return
eads@0 416 * the form item for a single element for this field
eads@0 417 */
eads@0 418 function mee_widget(&$form, &$form_state, $field, $items, $delta = 0) {
tom@5 419 if (isset($items[$delta]['value'])) {
tom@5 420 $items[$delta]['value'] = scald_sas_to_rendered($items[$delta]['value'], $field['mee_scald_editor_context'], TRUE);
tom@5 421 }
eads@0 422 $element = array(
eads@0 423 '#type' => $field['widget']['type'],
tom@5 424 '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
eads@0 425 );
tom@5 426
eads@0 427 return $element;
eads@0 428 }
eads@0 429
eads@0 430 /**
eads@0 431 * Process an individual element.
eads@0 432 *
eads@0 433 * Build the form element. When creating a form using FAPI #process,
eads@0 434 * note that $element['#value'] is already set.
eads@0 435 *
eads@0 436 * The $fields array is in $form['#field_info'][$element['#field_name']].
eads@0 437 */
eads@0 438 function mee_textarea_process($element, $edit, $form_state, $form) {
eads@0 439 drupal_add_css(drupal_get_path('module', 'mee') .'/css/mee.css');
franck@8 440 drupal_add_js(drupal_get_path('module', 'mee') .'/mee.js');
franck@11 441 $element['mee'] = array(
franck@11 442 '#type' => 'markup',
franck@11 443 '#prefix' => '<div class="mee-wrap-editor-library">',
franck@11 444 '#suffix' => '</div>',
franck@11 445 );
franck@11 446
eads@0 447 $field = $form['#field_info'][$element['#field_name']];
eads@0 448 $field_key = $element['#columns'][0];
franck@11 449 $element['mee']['ressource_manager'] = array(
franck@14 450 '#type' => 'markup',
franck@11 451 '#weight' => 0.5,
franck@14 452 '#theme' => 'mee_ressource_manager'
franck@11 453 );
franck@14 454
franck@14 455
franck@14 456 if (!isset($element['#value']['mee']['ressource_manager'])) {
franck@14 457 $element['#value']['mee']['ressource_manager'] = array();
franck@14 458 // Restore/Generate the associated ressources in a proper order
franck@14 459 $query = "SELECT * FROM {mee_ressources} WHERE content_nid=%d AND field='%s' ORDER BY weight ASC";
franck@14 460 $result = db_query($query, $form['nid']['#value'], $element['#field_name']);
franck@14 461 while ($item = db_fetch_object($result)) {
franck@14 462 $element['#value']['mee']['ressource_manager'][$item->atom_sid] = (array)$item;
franck@14 463 }
franck@14 464 $element['#value']['mee']['ressource_manager'][0] = array('weight' => 0);
franck@14 465 }
franck@14 466
franck@14 467 foreach($element['#value']['mee']['ressource_manager'] as $sid => $item) {
franck@14 468 $atom = scald_fetch($sid);
franck@14 469 $title = $atom->title;
franck@14 470
franck@14 471 $element['mee']['ressource_manager'][$sid] = array(
franck@14 472 'title' => array(
franck@14 473 '#type' => 'markup',
franck@14 474 '#value' => $title,
franck@14 475 ),
franck@14 476 'required' => array(
franck@14 477 '#type' => 'select',
franck@14 478 '#options' => array(t('Optional'), t('Required')),
franck@14 479 '#default_value' => $item['required']
franck@14 480 ),
franck@14 481 'weight' => array(
franck@14 482 '#type' => 'weight',
franck@14 483 '#default_value' => $item['weight'],
franck@14 484 ),
franck@14 485 '#weight' => $item['weight']
franck@14 486 );
franck@14 487 }
franck@14 488
franck@14 489 // And now we add the separator
franck@11 490 $element['mee']['ressource_manager'][0] = array(
franck@11 491 'title' => array(
franck@11 492 '#type' => 'markup',
franck@14 493 '#value' => t('< Primaire / Secondaire >'),
franck@14 494 ),
franck@14 495 'required' => array(
franck@14 496 '#type' => 'markup',
franck@14 497 '#value' => '-'
franck@11 498 ),
franck@11 499 'weight' => array(
franck@14 500 '#type' => 'weight',
franck@14 501 '#prefix' => '<div class="mee-rm-separator">',
franck@14 502 '#suffix' => '</div>'
franck@14 503 ),
franck@14 504 '#weight' => $element['#value']['mee']['ressource_manager'][0]['weight']
franck@11 505 );
franck@14 506 if ($element['#value'][$field_key]) {
franck@14 507 $element['#value']['mee'][$field_key] = $element['#value'][$field_key];
franck@14 508 }
franck@11 509 $element['mee'][$field_key] = array(
eads@0 510 '#type' => 'textarea',
franck@14 511 '#default_value' => isset($element['#value']['mee'][$field_key]) ? $element['#value']['mee'][$field_key] : NULL,
eads@0 512 '#rows' => !empty($field['widget']['rows']) ? $field['widget']['rows'] : 10,
eads@0 513 '#weight' => 0,
eads@0 514 // The following values were set by the content module and need
eads@0 515 // to be passed down to the nested element.
eads@0 516 '#title' => $element['#title'],
eads@0 517 '#description' => $element['#description'],
eads@0 518 '#required' => $element['#required'],
eads@0 519 '#field_name' => $element['#field_name'],
eads@0 520 '#type_name' => $element['#type_name'],
eads@0 521 '#delta' => $element['#delta'],
eads@0 522 '#columns' => $element['#columns'],
eads@0 523 '#dnd-enabled' => TRUE,
eads@0 524 '#dnd-settings' => array(
eads@0 525 'drop_selector' => '#'. $element['#id'] .' .drop',
eads@0 526 'url' => $field['mee_dnd_callback_url'],
eads@0 527 ),
eads@0 528 );
eads@0 529
eads@0 530 if (!empty($field['mee_processing'])) {
eads@0 531 $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format';
eads@0 532 $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : FILTER_FORMAT_DEFAULT;
eads@0 533 $parents = array_merge($element['#parents'] , array($filter_key));
franck@11 534 $element['mee'][$filter_key] = filter_form($format, 1, $parents);
franck@11 535 $element['mee'][$filter_key]['#prefix'] = '<div class="mee-filter-form">';
franck@11 536 $element['mee'][$filter_key]['#suffix'] = '</div>';
eads@0 537 }
eads@0 538
eads@0 539 // Used so that hook_field('validate') knows where to flag an error.
eads@0 540 $element['_error_element'] = array(
eads@0 541 '#type' => 'value',
eads@0 542 '#value' => implode('][', array_merge($element['#parents'], array($field_key))),
eads@0 543 );
defr@20 544 $short = $element['#value']['short'] ? $element['#value']['short'] : $element['#value']['mee']['short'];
franck@11 545 $element['mee']['short'] = array(
franck@11 546 '#type' => 'textarea',
defr@18 547 '#title' => t('Short content'),
franck@11 548 '#rows' => 5,
defr@18 549 '#weight' => -100,
defr@20 550 '#default_value' => $short
franck@11 551 );
eads@0 552
eads@0 553
eads@0 554 return $element;
eads@0 555 }
eads@0 556
eads@0 557 /**
eads@0 558 * FAPI theme for an individual text elements.
eads@0 559 *
eads@0 560 * The textfield or textarea is already rendered by the
eads@0 561 * textfield or textarea themes and the html output
eads@0 562 * lives in $element['#children']. Override this theme to
eads@0 563 * make custom changes to the output.
eads@0 564 *
eads@0 565 * $element['#field_name'] contains the field name
eads@0 566 * $element['#delta] is the position of this element in the group
eads@0 567 */
eads@0 568 function theme_mee_textarea($element) {
eads@0 569 return $element['#children'];
eads@0 570 }
tom@2 571
franck@11 572 function theme_mee_ressource_manager(&$form) {
franck@11 573 static $count = 0;
franck@11 574 $id = 'mee-ressource-manager-'. $count;
franck@11 575 drupal_add_tabledrag($id, 'order', 'sibling', 'mee-rm-weight');
franck@11 576 $count++;
franck@14 577 $header = array('', t('Title'), t('Required'), t('Weight'));
franck@11 578 $rows = array();
franck@11 579 foreach(element_children($form) as $key) {
franck@11 580 $form[$key]['weight']['#attributes']['class'] = 'mee-rm-weight';
franck@11 581
franck@11 582 $row = array('');
franck@11 583 $row[] = drupal_render($form[$key]['title']);
franck@14 584 $row[] = drupal_render($form[$key]['required']);
franck@11 585 $row[] = drupal_render($form[$key]['weight']);
franck@11 586 $rows[] = array('data' => $row, 'class' => 'draggable');
franck@11 587 }
franck@11 588 $output = theme('table', $header, $rows, array(
franck@11 589 'id' => $id,
franck@11 590 'class' => 'mee-ressource-manager'
franck@12 591 ),
franck@12 592 t('Ressource Manager')
franck@12 593 );
franck@11 594 $output .= drupal_render($form);
franck@11 595 return $output;
franck@11 596 }
tom@2 597
franck@14 598 function _mee_load_ressources($node, $field, &$item) {
franck@14 599 $results = db_query("
franck@14 600 SELECT atom_sid, weight
franck@14 601 FROM {mee_ressources}
franck@14 602 WHERE content_nid=%d AND field='%s'",
franck@14 603 array(
franck@14 604 ':nid' => $node->nid,
franck@14 605 ':field' => $field['field_name']
franck@14 606 )
franck@14 607 );
franck@14 608 $item['ressource_manager'] = array();
franck@14 609 while($r = db_fetch_object($results)) {
franck@14 610 $item['ressource_manager'][$r->atom_sid] = array('weight' => $r->weight);
franck@14 611 }
franck@14 612 $item['ressource_manager'][0] = array('weight' => 0);
franck@14 613 }
tom@2 614
tom@2 615
tom@2 616 /*******************************************************************************
tom@2 617 * SCALD HOOK IMPLEMENTATIONS
tom@2 618 ******************************************************************************/
tom@2 619
tom@2 620 /**
tom@2 621 * Implementation of hook_scald_provider().
tom@2 622 */
tom@2 623 function mee_scald_provider() {
tom@2 624 return array(
tom@2 625 'atoms' => array(
tom@5 626 'composite' => array(
tom@5 627 t('The MEE CCK field.'),
tom@5 628 ),
tom@2 629 ),
tom@2 630 );
tom@2 631 }
tom@2 632
tom@2 633
tom@2 634
tom@2 635 /**
tom@2 636 * Implementation of hook_scald_register_atom().
tom@2 637 */
tom@2 638 function mee_scald_register_atom($atom, $mode) {
tom@2 639
tom@2 640 } // end mee_scald_register_atom()
tom@2 641
tom@2 642
tom@2 643
tom@2 644 /**
tom@2 645 * Implementation of hook_scald_update_atom().
tom@2 646 */
tom@2 647 function mee_scald_update_atom($atom, $mode) {
tom@2 648
tom@2 649 } // end mee_scald_update_atom()
tom@2 650
tom@2 651
tom@2 652
tom@2 653 /**
tom@2 654 * Implementation of hook_scald_unregister_atom().
tom@2 655 */
tom@2 656 function mee_scald_unregister_atom($atom, $mode) {
tom@2 657
tom@2 658 } // end mee_scald_unregister_atom()
tom@2 659
tom@2 660
tom@2 661
tom@2 662 /**
tom@2 663 * Implementation of hook_scald_fetch().
tom@2 664 */
tom@2 665 function mee_scald_fetch(&$atom) {
tom@2 666 $atom->thumbnail_source = drupal_get_path('module', 'scald_composites') . '/assets/thumbnail_composite.png';
tom@2 667 } // end mee_scald_fetch()
tom@2 668
tom@2 669
tom@2 670
tom@2 671 /**
tom@2 672 * Implementation of hook_scald_prerender().
tom@2 673 */
tom@2 674 function mee_scald_prerender(&$atom, $mode) {
tom@2 675
tom@2 676 } // end mee_scald_prerender()
tom@2 677