Projet

Général

Profil

Révision 4853591f

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/fivestar/fivestar.module
35 35
    'type'              => MENU_NORMAL_ITEM,
36 36
    'file'              => 'includes/fivestar.admin.inc',
37 37
  );
38
  $items['fivestar/preview/color'] = array(
39
    'page callback'     => 'fivestar_preview_color',
40
    'access callback'   => 'user_access',
41
    'access arguments'  => array('administer site configuration'),
42
    'type'              => MENU_CALLBACK,
43
    'file'              => 'includes/fivestar.color.inc',
44
  );
45 38

  
46 39
  return $items;
47 40
}
......
178 171
    }
179 172

  
180 173
    // Moving the calculationg after saving/deleting the vote but before getting the votes.
181
    votingapi_recalculate_results($entity_type, $id);    
174
    votingapi_recalculate_results($entity_type, $id);
182 175
    return fivestar_get_votes($entity_type, $id, $tag, $uid);
183 176
  }
184 177
}
......
306 299
function fivestar_fivestar_access($entity_type, $id, $tag, $uid) {
307 300
  // Check to see if there is a field instance on this entity.
308 301
  $fields = field_read_fields(array('module' => 'fivestar'));
309
  foreach($fields as $field) {
302
  foreach ($fields as $field) {
310 303
    if ($field['settings']['axis'] == $tag) {
311 304
      $params = array(
312 305
        'entity_type' => $entity_type,
313 306
        'field_name' => $field['field_name'],
314 307
      );
315 308
      $instance = field_read_instances($params);
316
      if(!empty($instance)) {
309
      if (!empty($instance)) {
317 310
        return TRUE;
318 311
      }
319 312
    }
320 313
  }
321 314
}
322 315

  
316
/**
317
 * Implementation of hook_form_comment_form_alter().
318
 *
319
 * This hook removes the parent node, together with the fivestar field, from
320
 * the comment preview page. If this is left in, when the user presses the
321
 * "Save" button after the preview page has been displayed, the fivestar widget
322
 * gets the input rather than the comment; the user's input is lost. Based on a
323
 * suggestion by ChristianAdamski in issue 1289832-3.
324
 */
325
function fivestar_form_comment_form_alter(&$form, &$form_state, $form_id) {
326
  $is_fivestar = FALSE;
327
  if (isset($form['comment_output_below'])) {
328
    foreach($form['comment_output_below'] as $key => $value) {
329
      if (is_array($value) && !empty($value['#field_type'])) {
330
        if ($value['#field_type'] =='fivestar') {
331
          $is_fivestar = TRUE;
332
          $fivestar_key = $key;
333
        }
334
      }
335
    }
336
  }
337
  if ($is_fivestar) {
338
    unset($form['comment_output_below'][$fivestar_key]);
339
  }
340
}
341

  
323 342
/**
324 343
 * Implementation of hook_fivestar_widgets().
325 344
 *
......
334 353
function fivestar_fivestar_widgets() {
335 354
  $files = &drupal_static(__FUNCTION__);
336 355
  if (!isset($files)) {
337
    $widgets_directory = drupal_get_path('module', 'fivestar') .'/widgets';
356
    $widgets_directory = drupal_get_path('module', 'fivestar') . '/widgets';
338 357
    $files = file_scan_directory($widgets_directory, '/\.css$/');
339 358
  }
340 359
  $widgets = array();
......
396 415
    '#widget' => isset($settings['widget']) ? $settings['widget'] : array('name' => 'default', 'css' => 'default'),
397 416
    '#values' => $values,
398 417
    '#settings' => $settings,
418
    '#description' => $settings['description'],
399 419
  );
400 420

  
401 421
  $form['fivestar_submit'] = array(
......
427 447
 * AJAX submit handler for fivestar_custom_widget
428 448
 */
429 449
function fivestar_ajax_submit($form, $form_state) {
430
  _fivestar_update_field_value($form_state['settings']['content_type'], $form_state['settings']['entity'], $form_state['settings']['field_name'], $form_state['settings']['langcode'], $form_state['values']['vote']);
431
  $votes = _fivestar_cast_vote($form_state['settings']['content_type'], $form_state['settings']['content_id'], $form_state['values']['vote'], $form_state['settings']['tag']);
450
  if (!empty($form_state['settings']['content_id'])) {
451
    _fivestar_update_field_value($form_state['settings']['content_type'], $form_state['settings']['entity'], $form_state['settings']['field_name'], $form_state['settings']['langcode'], $form_state['values']['vote']);
452
    $votes = _fivestar_cast_vote($form_state['settings']['content_type'], $form_state['settings']['content_id'], $form_state['values']['vote'], $form_state['settings']['tag']);
453
  }
454

  
432 455

  
433 456
  $values = array();
434 457
  $values['user'] = isset($votes['user']['value']) ? $votes['user']['value'] : 0;
......
510 533
    '#options' => $options,
511 534
    '#required' => $element['#required'],
512 535
    '#theme' => 'fivestar_select',
536
    '#attributes' => $element['#attributes'],
513 537
    '#default_value' => _fivestar_get_element_default_value($element),
514 538
    '#weight' => -2,
515 539
  );
......
568 592
      $class[] = 'fivestar-user-stars';
569 593
      break;
570 594
    case 'smart':
571
      $class[] = 'fivestar-smart-stars '. ($values['user'] ? 'fivestar-user-stars' : 'fivestar-average-stars');
595
      $class[] = 'fivestar-smart-stars ' . ($values['user'] ? 'fivestar-user-stars' : 'fivestar-average-stars');
572 596
      break;
573 597
    case 'dual':
574 598
      $class[] = 'fivestar-combo-stars';
......
688 712
 */
689 713
function fivestar_validate($element, &$form_state) {
690 714
  if ($element['#required'] && (empty($element['#value']) || $element['#value'] == '-')) {
691
    form_error($element, t('!name field is required.', array('!name' => $element['#title'])));
715
    form_error($element, t('@name field is required.', array('@name' => $element['#title'])));
692 716
  }
693 717
}
694 718

  
......
711 735
  $tags_exploded = explode(',', $tags_txt);
712 736

  
713 737
  $tags = array();
714
  $got_vote = false;
738
  $got_vote = FALSE;
715 739
  foreach ($tags_exploded as $tag) {
716 740
    $tag_trimmed = trim($tag);
717 741
    if ($tag_trimmed) {
718 742
      $tags[$tag_trimmed] = $tag_trimmed;
719 743
      if ($tag_trimmed == 'vote') {
720
        $got_vote = true;
744
        $got_vote = TRUE;
721 745
      }
722 746
    }
723 747
  }
......
771 795
    }
772 796
  }
773 797

  
798
  // Add entityreference support.
799
  if (module_exists('entityreference')) {
800
    $field_names = array_keys(field_read_fields(array('module' => 'entityreference')));
801
    if (!empty($field_names)) {
802
      $field_instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle, 'field_name' => $field_names));
803
      if (!empty($field_instances)) {
804
        foreach ($field_instances as $field_instance) {
805
          $options[$field_instance['field_name']] = array(
806
            'title' => t('Entity reference: @field', array('@field' => $field_instance['field_name'])),
807
            'callback' => '_fivestar_target_entityreference'
808
          );
809
        }
810
      }
811
    }
812
  }
813

  
814
  // Add user reference support.
815
  if (module_exists('user_reference')) {
816
    $field_names = array_keys(field_read_fields(array('module' => 'user_reference')));
817
    if (!empty($field_names)) {
818
      $field_instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle, 'field_name' => $field_names));
819
      if (!empty($field_instances)) {
820
        foreach ($field_instances as $field_instance) {
821
          $options[$field_instance['field_name']] = array(
822
            'title' => t('User reference: @field', array('@field' => $field_instance['field_name'])),
823
            'callback' => '_fivestar_target_user_reference'
824
          );
825
        }
826
      }
827
    }
828
  }
829

  
774 830
  // Add comment module support.
775 831
  if ($instance['entity_type'] == 'comment') {
776 832
    $options['parent_node'] = array(
......
784 840

  
785 841
/**
786 842
 *
787
 * @return (array) array('entity_type', 'entity_id')
843
 * @return array
844
 *   array('entity_type', 'entity_id').
788 845
 */
789 846
function _fivestar_target_node_reference($entity, $field, $instance, $langcode) {
790 847
  $target = array();
......
798 855
  return $target;
799 856
}
800 857

  
858
/**
859
 * @return (array) array('entity_type', 'entity_id')
860
 */
861
function _fivestar_target_entityreference($entity, $field, $instance, $langcode) {
862
  $target = array();
863

  
864
  $entityreference = $instance['settings']['target'];
865

  
866
  // Retrieve entity settings for the referenced field.
867
  $field_info = field_info_field($entityreference);
868

  
869
  if (isset($entity->{$entityreference}[$langcode][0]) && isset($entity->{$entityreference}[$langcode][0]['target_id']) && is_numeric($entity->{$entityreference}[$langcode][0]['target_id'])) {
870
    $target['entity_id'] = $entity->{$entityreference}[$langcode][0]['target_id'];
871
    $target['entity_type'] = $field_info['settings']['target_type'];
872
  }
873

  
874
  return $target;
875
}
876

  
877
/**
878
 *
879
 * @return array
880
 *   array('entity_type', 'entity_id').
881
 */
882
function _fivestar_target_user_reference($entity, $field, $instance, $langcode) {
883
  $target = array();
884

  
885
  $user_reference = $instance['settings']['target'];
886
  if (isset($entity->{$user_reference}[$langcode][0]) && is_numeric($entity->{$user_reference}[$langcode][0]['uid'])) {
887
    $target['entity_id'] = $entity->{$user_reference}[$langcode][0]['uid'];
888
    $target['entity_type'] = 'user';
889
  }
890

  
891
  return $target;
892
}
893

  
801 894
function _fivestar_target_comment_parent_node($entity, $field, $instance, $langcode) {
802 895
  return array(
803 896
    'entity_id' => $entity->nid,

Formats disponibles : Unified diff