Conjunto de cambios 1dd3f69 en sipes para modules_contrib/editablefields/editablefields.module
- Fecha y hora:
- 26/05/2016 19:21:52 (hace 8 años)
- Branches:
- stable, version-3.0
- Children:
- dedbde1
- Parents:
- 663b989
- Fichero:
-
- 1 editado
Leyenda
- No modificado
- Añadido
- Eliminado
-
modules_contrib/editablefields/editablefields.module
r177a560 r1dd3f69 1 1 <?php 2 // $Id: editablefields.module,v 1.3.2.17.2.10 2010/01/18 08:48:10 markfoodyburton Exp $ 2 3 3 4 /** … … 7 8 8 9 /** 9 * Implementation of hook_perm.10 *11 * @return array12 * An array of permissions that this module provides.13 */14 function editablefields_perm() {15 return array('administer editablefields');16 }17 18 /**19 * Implementation of hook_ctools_plugin_directory().20 *21 * @param $module22 * @param $plugin_type23 * @return string24 */25 function editablefields_ctools_plugin_directory($module, $plugin_type) {26 27 if ($plugin_type == 'export_ui') {28 return "plugins/export_ui";29 }30 31 if ($module == 'editablefields' && !empty($plugin_type)) {32 return "plugins/$plugin_type";33 }34 }35 36 37 /**38 * Implementation of hook_ctools_plugin_api().39 *40 * Tell Ctools that we support the default_editablefields_presets API.41 */42 function editablefields_ctools_plugin_api($owner, $api) {43 if ($owner == 'editablefields' && $api == 'default_editablefields_presets') {44 return array('version' => 1);45 }46 }47 48 /**49 * Implementation of hook_default_editablefields_preset().50 *51 * Provide a couple of default presets.52 */53 function editablefields_default_editablefields_preset() {54 $export = array();55 56 $export['modal'] = (object) array(57 'api_version' => 1,58 'name' => 'modal',59 'description' => 'Display the field form in a Modal Dialog',60 'config' => array(61 'editable_type' => 'modal',62 ),63 );64 65 $export['html'] = (object) array(66 'api_version' => 1,67 'name' => 'html',68 'description' => 'Display the field form inline',69 'config' => array(70 'editable_type' => 'html',71 )72 );73 74 return $export;75 }76 77 /**78 * Implementation of hook_menu_alter().79 */80 function editablefields_menu_alter(&$items) {81 // takeover the filefield ahah callback. This is a temporary hackish solution.82 if (isset($items['filefield/ahah/%/%/%'])) {83 $items['filefield/ahah/%/%/%'] = array(84 'page callback' => 'editablefields_filefield_js',85 ) + $items['filefield/ahah/%/%/%'];86 }87 }88 89 /**90 10 * Implementation of hook_menu(). 91 11 */ 92 12 function editablefields_menu() { 13 global $user; 93 14 $items = array(); 94 15 … … 99 20 'type' => MENU_CALLBACK, 100 21 'title' => 'ajax view', 101 );22 ); 102 23 $items['editablefields_html'] = array( 103 24 'page callback' => 'editablefields_html', … … 105 26 'type' => MENU_CALLBACK, 106 27 'title' => 'ajax form', 107 );28 ); 108 29 $items['editablefields_submit'] = array( 109 30 'page callback' => 'editablefields_submit', … … 111 32 'type' => MENU_CALLBACK, 112 33 'title' => 'ajax submit', 113 ); 114 115 $plugins = editablefields_get_responders(); 116 foreach($plugins as $plugin_name => $plugin) { 117 foreach($plugin['hook_menu'] as $plugin_item_path => $plugin_item) { 118 $items[$plugin_item_path] = $plugin_item + array( 119 'title' => $plugin['title'], 120 'file' => $plugin['file'], 121 'file path' => $plugin['path'], 122 'type' => MENU_CALLBACK, 123 ); 124 } 125 } 34 ); 126 35 127 36 return $items; … … 132 41 */ 133 42 function editablefields_theme() { 134 135 $items = array(); 136 137 $plugins = editablefields_get_editables(); 138 foreach($plugins as $plugin_name => $plugin) { 139 if (!empty($plugin['theme'])) { 140 $items = array_merge($items, $plugin['theme']); 141 } 142 } 143 144 return $items; 145 } 146 147 /* 148 function editablefields_theme_registry_alter(&$items) { 149 $items['views_view_field']['function'] = 'editablefields_views_view_field'; 150 } 151 */ 43 return array( 44 'editablefields_formatter_editable' => array( 45 'arguments' => array('element' => NULL), 46 'function' => 'theme_editablefields_formatter_editable', 47 ), 48 'editablefields_formatter_editable_html' => array( 49 'arguments' => array('element' => NULL), 50 'function' => 'theme_editablefields_formatter_editable', 51 ), 52 'editablefields_formatter_clicktoedit' => array( 53 'arguments' => array('element' => NULL), 54 'function' => 'theme_editablefields_formatter_editable', 55 ), 56 ); 57 } 152 58 153 59 /** … … 155 61 */ 156 62 function editablefields_field_formatter_info() { 157 $items = array();158 159 $plugins = editablefields_get_editables();160 foreach($plugins as $plugin_name => $plugin) {161 if (!empty($plugin['formatter_info'])) {162 $items = array_merge($items, $plugin['formatter_info']);163 }164 }165 166 return $items;167 }168 169 /**170 * Implementation of hook_content_build_modes().171 *172 * @return array173 */174 //agrega los widgets en editable(node type)175 function editablefields_content_build_modes() {176 // Tell CCK about our "build" modes so that users can specify177 // how they want the text in their modal/other link to be formatted178 // on the Display Fields tab of the CCK admin.179 $build_modes = array();180 $plugins = editablefields_get_responders();181 if (!empty($plugins)) {182 $build_modes = array(183 'editablefields' => array(184 'title' => t('Editable mode'),185 'build modes' => array(),186 ),187 );188 foreach($plugins as $plugin_name => $plugin) {189 foreach($plugin['build modes'] as $mode_name => $mode_info) {190 $build_modes['editablefields']['build modes'][$mode_name] = $mode_info;191 }192 }193 }194 return $build_modes;195 }196 197 /**198 * Implementation of hook_form_alter().199 */200 //elimina los widgets editables201 function editablefields_form_alter(&$form, &$form_state, $form_id) {202 if ($form_id == 'content_display_overview_form') {203 // Remove editable field formatters from the options.204 if ($form['#contexts'] == 'editablefields') {205 $formatters = editablefields_field_formatter_info();206 foreach($form as $key => &$element) {207 if (substr($key, 0, 6) == 'field_') {208 foreach($element as $setting_name => &$setting) {209 if (!empty($setting['format'])) {210 foreach($formatters as $formatter_name => $formatter) {211 unset($setting['format']['#options'][$formatter_name]);212 unset($setting['format']['base']['#options'][$formatter_name]);213 }214 }215 }216 }217 }218 }219 }220 221 }222 223 224 225 /**226 * Editablefields version of replace CTools command.227 * It uses the228 *229 * The replace command will replace a portion of the current document230 * with the specified HTML.231 *232 * @param $html233 * The data to use with the jquery replace() function.234 *235 * @return array236 */237 function ctools_ajax_command_replace_active_element($index, $html) {238 63 return array( 239 'command' => 'replace_active_element', 240 'active_elem_index' => $index, 241 'data' => $html, 242 ); 243 } 244 64 'editable' => array( 65 'label' => t('Editable (Ajax)'), 66 'field types' => array_keys(_content_field_types()), 67 ), 68 'editable_html' => array( 69 'label' => t('Editable (HTML)'), 70 'field types' => array_keys(_content_field_types()), 71 ), 72 'clicktoedit' => array( 73 'label' => t('Click to Edit'), 74 'field types' => array_keys(_content_field_types()), 75 ), 76 ); 77 } 245 78 246 79 /** 247 80 * Theme the editable field. 248 81 */ 249 /*250 82 function theme_editablefields_formatter_editable($element) { 251 252 83 static $js_ready; 253 84 254 85 $field_name = $element['#field_name']; 255 86 $field = content_fields($field_name); 256 257 $revision = !empty($element['#node']->vid) ? $element['#node']->vid : NULL; 258 $node = node_load($element['#node']->nid, $revision); 87 $node = $element['#node']; 259 88 $delta = $element['#item']['#delta']; 260 89 261 // to disable overriding textareas just set this variable to 0 262 if (variable_get('editablefields_textareas_resizable_threshold', 25)) { 263 static $textareas_count = 0; 264 if ( 265 $field['type'] == 'text' && $field['widget']['type'] == 'text_textarea') { 266 if ($textareas_count++ 267 >= variable_get('editablefields_textareas_resizable_threshold', 25)) { 268 drupal_add_js(drupal_get_path('module', 'editablefields') 269 . '/editablefields_overrides.js'); 270 } 271 } 90 if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { 272 91 } 273 92 … … 288 107 $js_ready = TRUE; 289 108 drupal_add_js('misc/jquery.form.js'); 290 drupal_add_js( 291 drupal_get_path('module', 'editablefields') . '/editablefields.js'); 292 drupal_add_css( 293 drupal_get_path('module', 'editablefields') . '/editablefields.css'); 109 drupal_add_js(drupal_get_path('module', 'editablefields') . '/editablefields.js'); 110 drupal_add_css(drupal_get_path('module', 'editablefields') . '/editablefields.css'); 294 111 295 112 $settings = array( 296 113 'url_html' => url('editablefields_html', array('absolute' => TRUE)), 297 'url_submit' => url('editablefields_submit', 298 array('absolute' => TRUE)), 114 'url_submit' => url('editablefields_submit', array('absolute' => TRUE)), 299 115 'url_view' => url('editablefields_view', array('absolute' => TRUE)), 300 'clicktoedit_message' => theme('editablefields_clicktoedit_message'), 301 'clicktoedit_message_empty' => theme('editablefields_clicktoedit_message_empty'), 116 'clicktoedit_message' => '<div class="editablefields_clicktoedit_message">'. t('[edit]') .'</div>', 302 117 ); 303 118 drupal_add_js(array('editablefields' => $settings), 'setting'); 304 119 } 305 306 // [andreiashu] not sure how this works exactly but it does...307 if (content_handle('widget', 'multiple values', $field)308 != CONTENT_HANDLE_CORE) {309 if ($delta != 0) {310 return;311 }312 }313 314 120 $theme = $formatter['module'] . '_formatter_' . $formatter_name; 315 121 $class = "editablefields"; 316 if ($element['#formatter'] == 'editable') { 317 $class .= " ajax-editable"; 318 } 319 elseif ($element['#formatter'] == 'clicktoedit') { 122 if ($element['#formatter'] == 'clicktoedit') { 320 123 $class .= " clicktoedit"; 321 124 } … … 323 126 $class .= " editablefields-html-load"; 324 127 } 325 326 $pre = '<div class="' . $class . '" nid="' . $node->nid . '" field="' 327 . $field_name . '" delta="' . $delta . '">'; 128 // CORE handling shoudl have a div on each, 129 // MODULE handling should have a div surounding all elements (treat it as 130 // one field) (So, we'll arrainge for the JS to remove the rest!) 131 if (content_handle('widget', 'multiple values', $field) != CONTENT_HANDLE_CORE) { 132 if ($delta != 0) { 133 $class = "editablefields editablefields_REMOVE"; 134 } 135 } 136 137 $pre = '<div class="' . $class . '" nid="' . $node->nid . '" field="' . $field_name . '" delta="' . $delta . '">'; 328 138 $post = '</div>'; 329 139 330 140 if ($element['#formatter'] != 'editable_html') { 331 $themed_element = theme($theme, $element); 332 333 // add the edit link for clicktoedit formatters 334 if ($element['#formatter'] == 'clicktoedit') { 335 if (!empty($themed_element)) { 336 $pre .= theme('editablefields_clicktoedit_message'); 337 } 338 else { 339 $pre .= theme('editablefields_clicktoedit_message_empty'); 340 } 341 } 342 return $pre . $themed_element . $post; 141 return $pre . theme($theme, $element) . $post; 343 142 } 344 143 else { 345 144 // $node seems to be incomplete, so we reload it 346 $node = node_load($node->nid, $revision); 347 return $pre 348 . drupal_get_form('editablefields_form', $node, $field_name, $delta) 349 . $post; 350 } 351 } 352 } 353 } 354 */ 355 356 function theme_editablefields_clicktoedit_message() { 357 return '<span class="editablefields_clicktoedit_message editablefields-hide">' 358 . t('[edit]') . '</span>'; 359 } 360 361 function theme_editablefields_clicktoedit_message_empty() { 362 return '<span class="editablefields_clicktoedit_message">' . t('[edit]') 363 . '</span>'; 145 $node = node_load($node->nid); 146 return $pre . drupal_get_form('editablefields_form', $node, $field_name, $delta) . $post; 147 } 148 } 149 } 364 150 } 365 151 … … 367 153 * Implementation of hook_forms(). 368 154 */ 369 function editablefields_forms( $form_id) {155 function editablefields_forms() { 370 156 $forms = array(); 371 157 $forms['editablefields_form'] = array( … … 381 167 function editablefields_form_builder(&$form_state, $node, $field_name, $delta) { 382 168 $field = content_fields($field_name); 169 383 170 $form = array('#node' => $node); 384 171 // $form_state = array('values' => array($field['field_name'] => $default_value)); 385 172 module_load_include('inc', 'content', 'includes/content.node_form'); 386 173 $form['#field_info'] = array($field['field_name'] => $field); … … 391 178 unset($form[$field_name][0]['#title']); 392 179 } 393 394 $form['editablefields_node_nid'] = array(395 '#type' => 'hidden',396 '#value' => $node->nid,397 );398 180 399 181 $form['#field_info'] = array($field['field_name'] => $field); … … 415 197 return $form; 416 198 } 417 418 199 /** 419 200 * Menu callback: ajax view. 420 201 */ 421 202 function editablefields_view() { 422 $output = ''; 203 423 204 $nid = arg(1); 424 205 $field_name = arg(2); … … 426 207 $node = node_load($nid); 427 208 drupal_set_header('Content-Type: text; charset=utf-8'); 428 209 // $html = node_view($node, FALSE, FALSE, FALSE); 429 210 // this required traversing the entire node to get the field (and doesn't work 430 211 // for checkboxes anyway) … … 432 213 $field = content_fields($field_name, $node->type); 433 214 434 $field['display_settings']['label']['format'] ='hidden';215 $field['display_settings']['label']['format']='hidden'; 435 216 // We have 2 reasonable choices here. We COULD use 'clicktoedit' and end up 436 217 // with the same HTML - then we could strip that HTML down to remove the … … 439 220 // or we can simply use the 'defualt' formatter - which wont have the click to 440 221 // edit inside it - and is hard coded into this module (for now) anyway! 441 $field['display_settings']['full']['format'] ='default';442 $html = content_view_field($field,$node);443 222 $field['display_settings']['full']['format']='default'; 223 $html=content_view_field($field,$node); 224 444 225 $messages = drupal_get_messages('status', TRUE); 445 226 if (count($messages) > 0) { … … 452 233 453 234 $object = new stdClass(); 454 $object->content = 455 $output . $html . drupal_render($node->content[$field_name]); 235 $object->content = $output . $html.drupal_render($node->content[$field_name]); 456 236 drupal_json($object); 457 237 exit(); … … 494 274 $node = node_load($nid); 495 275 496 $node_options = variable_get(497 'node_options_' . $node->type, array('status', 'promote'));498 $node->revision = in_array('revision', $node_options);499 if ($node->revision) {500 $node->log = t(501 '%field_name updated by editablefields.',502 array('%field_name' => $field_name)503 );504 }505 506 276 if (node_access('update', $node)) { 507 277 … … 517 287 * right value - I dislike this code - JMB */ 518 288 if (is_array($node->{$field_name})) { 519 $field = content_fields($field_name, $node->type); 520 521 $items = &$form_state['values'][$field_name]; 522 523 if (empty($items)) { 524 foreach (array_keys($field['columns']) as $column) { 525 if ($field['multiple']) { 526 $items[$delta][$column][] = NULL; 527 } 528 else { 529 $items[$column] = NULL; 530 } 531 } 532 } 533 534 if (isset($items['value'])) { 535 if (!($field['widget']['type'] == 'optionwidgets_buttons' && 536 $field['multiple'])) { 537 $items = array($items); 538 } 539 } 540 541 // go through content_set_empty if this is NOT a checkbox multi valued element 542 if (!($field['widget']['type'] == 'optionwidgets_buttons' && 543 $field['multiple'])) { 544 $items = content_set_empty($field, $items); 545 } 546 547 switch ($field['type']) { 548 case 'nodereference': 549 case 'userreference': 550 if ($field['multiple']) { 551 reset($field['columns']); 552 $items[key($field['columns'])] = array_pop($items); 553 } 554 break; 555 } 556 557 drupal_execute('editablefields_form', $form_state, $node, $field_name, 558 $delta 559 ); 560 289 if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { 290 if (empty($form_state['values'][$field_name])) { 291 $form_state['values'][$field_name]=array('value'=>0); 292 } 293 } else { 294 if (empty($form_state['values'][$field_name][0])) { 295 $form_state['values'][$field_name][0]=array('value'=>0); 296 } 297 } 298 299 drupal_execute('editablefields_form', $form_state, $node, $field_name, $delta); 300 561 301 $err = drupal_get_messages(); 562 302 563 303 if (count($err) > 0) { 564 304 drupal_set_header('HTTP/1.1 404 Not Found'); … … 572 312 } 573 313 574 // the matrix field identifies itself as being multivalue, but in fact, it is not. 575 if ((content_handle('widget', 'multiple values', $field) 576 == CONTENT_HANDLE_CORE) && ($field['type'] != matrix)) { 577 if ($node->{$field_name}[$delta] != 578 $form_state['values'][$field_name][0]) { 314 $field = content_fields($field_name); 315 if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) { 316 if ($node->{$field_name}[$delta] != $form_state['values'][$field_name][0]) { 579 317 $node->{$field_name}[$delta] = $form_state['values'][$field_name][0]; 580 318 node_save($node); … … 592 330 else { 593 331 drupal_set_header('HTTP/1.1 404 Not Found'); 594 print t('No field found, of name: %field', 595 array('%field' => $field_name)); 332 print t('No field found, of name: %field', array('%field' => $field_name)); 596 333 } 597 334 } … … 602 339 exit(); 603 340 } 604 605 606 /**607 * If the Remove button was clicked remove the file from the node.608 */609 function editablefields_filefield_js($type_name, $field_name, $delta) {610 if (!empty($_POST['editablefields_node_nid']) &&611 $node = node_load($_POST['editablefields_node_nid'])) {612 $remove_button_clicked = FALSE;613 foreach ($_POST as $key => $value) {614 // check if the remove button was clicked615 if (stripos($key, $field_name) === 0 &&616 stripos($key, '_filefield_remove') !== FALSE) {617 $remove_button_clicked = TRUE;618 break;619 }620 }621 622 if ($remove_button_clicked) {623 $field = $_POST[$field_name];624 $field = array_pop($field);625 $file = (object)field_file_load($field['fid']);626 627 // respect revision settings628 $node_options = variable_get(629 'node_options_' . $node->type, array('status', 'promote'));630 $node->revision = in_array('revision', $node_options);631 if ($node->revision) {632 $node->log = t('%field_name updated by editablefields.',633 array('%field_name' => $field_name));634 }635 636 $file->field_name = $field_name;637 $references = field_file_delete($file);638 639 $node->{$field_name}[$delta] = array();640 node_save($node);641 642 drupal_set_message(t('File %filename was removed from node.',643 array('%filename' => $file->filename)));644 }645 }646 647 filefield_js($type_name, $field_name, $delta);648 }649 650 /**651 * Implementation of hook_file_insert().652 */653 function editablefields_file_insert($file) {654 if (stripos($_GET['q'], 'filefield/ahah/') === 0 && !empty(655 $_POST['editablefields_node_nid']) &&656 $node = node_load($_POST['editablefields_node_nid'])) {657 $file_clone = (array)$file;658 field_file_save($node, $file_clone);659 660 $q_arr = explode('/', $_GET['q']);661 $field_name = $q_arr[3];662 $delta = $q_arr[4];663 664 $node->{$field_name}[$delta] = array(665 'fid' => $file->fid666 );667 668 // respect revision settings669 $node_options = variable_get(670 'node_options_' . $node->type, array('status', 'promote'));671 $node->revision = in_array('revision', $node_options);672 if ($node->revision) {673 $node->log = t('%field_name updated by editablefields.',674 array('%field_name' => $field_name));675 }676 677 node_save($node);678 }679 }680 681 682 function editablefields_formatter_get_settings($field_name, $type_name, $context) {683 $options = array();684 $value = 'editablefields:'. $type_name .':'. $context .':'. $field_name;685 $options['editablefields'] = variable_get($value . '_text_formatter', 'default');686 /*687 $options['repeat']['show_repeat_rule'] = variable_get($value .'_show_repeat_rule', 'show');688 $options['multiple']['multiple_number'] = variable_get($value .'_multiple_number', '');689 $options['multiple']['multiple_from'] = variable_get($value .'_multiple_from', '');690 $options['multiple']['multiple_to'] = variable_get($value .'_multiple_to', '');691 $options['fromto']['fromto'] = variable_get($value .'_fromto', 'both')692 */693 return $options;694 }695 696 /**697 * Returns all 'editables' plugins.698 *699 * @return array700 */701 function editablefields_get_responders() {702 ctools_include('plugins');703 $plugins = ctools_get_plugins('editablefields', 'responders');704 foreach($plugins as &$plugin) {705 // add defaults706 $plugin += array(707 'hook_menu' => array(),708 'formatter_info' => array(),709 );710 }711 return $plugins;712 }713 714 function editablefields_get_editables() {715 ctools_include('plugins');716 $plugins = ctools_get_plugins('editablefields', 'editables');717 return $plugins;718 }719 /**720 * Menu wildcard argument callback.721 */722 function editablefields_object_load($object_id, $editable) {723 $editables = editablefields_get_editables();724 $function = $editables[$editable]['entity callback'];725 return $function($object_id);726 }727 728 /**729 * Implementation of hook_views_api().730 */731 function editablefields_views_api() {732 return array(733 'api' => 2,734 'path' => drupal_get_path('module', 'editablefields') . '/includes/views',735 );736 }737 738 function editablefields_views_option_form(&$form, &$form_state, $editable) {739 $form['editablefields_allowed'] = array(740 '#title' => t('Make field editable'),741 '#description' => t('This will override any other link you have set.'),742 '#type' => 'checkbox',743 '#default_value' => '',744 );745 $responders = editablefields_get_responders();746 $options = array();747 748 foreach($responders as $responder) {749 $options[$responder['name']] = $responder['title'];750 }751 752 $form['editablefields_responder'] = array(753 '#title' => t('Editable Behavior'),754 '#description' => t('How would you like to edit this field?'),755 '#type' => 'select',756 '#options' => $options,757 '#dependency' => array('edit-options-editablefields-allowed' => array('1')),758 '#process' => array('views_process_dependency')759 );760 761 $form['editablefields_editable'] = array(762 '#type' => 'hidden',763 '#value' => $editable,764 );765 }
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.