Révision d756b39a
Ajouté par Assos Assos il y a environ 8 ans
drupal7/sites/all/modules/fivestar/fivestar.module | ||
---|---|---|
69 | 69 |
function fivestar_permission() { |
70 | 70 |
return array( |
71 | 71 |
'rate content' => array( |
72 |
'title' => t('rate content'), |
|
72 |
'title' => t('Use Fivestar to rate content'),
|
|
73 | 73 |
), |
74 | 74 |
); |
75 | 75 |
} |
... | ... | |
350 | 350 |
* suggestion by ChristianAdamski in issue 1289832-3. |
351 | 351 |
*/ |
352 | 352 |
function fivestar_form_comment_form_alter(&$form, &$form_state, $form_id) { |
353 |
$is_fivestar = FALSE;
|
|
353 |
$fivestar_field_keys = array();
|
|
354 | 354 |
if (isset($form['comment_output_below'])) { |
355 | 355 |
foreach($form['comment_output_below'] as $key => $value) { |
356 |
if (is_array($value) && !empty($value['#field_type'])) { |
|
357 |
if ($value['#field_type'] =='fivestar') { |
|
358 |
$is_fivestar = TRUE; |
|
359 |
$fivestar_key = $key; |
|
360 |
} |
|
356 |
if (is_array($value) && !empty($value['#field_type']) && $value['#field_type'] == 'fivestar') { |
|
357 |
$fivestar_field_keys[] = $key; |
|
361 | 358 |
} |
362 | 359 |
} |
363 | 360 |
} |
364 |
if ($is_fivestar) { |
|
365 |
unset($form['comment_output_below'][$fivestar_key]); |
|
361 |
if ($fivestar_field_keys) { |
|
362 |
foreach ($fivestar_field_keys as $key) { |
|
363 |
unset($form['comment_output_below'][$key]); |
|
364 |
} |
|
366 | 365 |
} |
367 | 366 |
} |
368 | 367 |
|
... | ... | |
440 | 439 |
|
441 | 440 |
$form_state['settings'] = $settings; |
442 | 441 |
|
442 |
// Define default settings. |
|
443 |
$default_settings = array( |
|
444 |
'allow_clear' => FALSE, |
|
445 |
// Taken from installation file. |
|
446 |
'allow_ownvote' => TRUE, |
|
447 |
'allow_revote' => TRUE, |
|
448 |
'autosubmit' => TRUE, |
|
449 |
'description' => '', |
|
450 |
'required' => FALSE, |
|
451 |
'stars' => 5, |
|
452 |
'tag' => 'vote', |
|
453 |
'widget' => array( |
|
454 |
'name' => 'default', |
|
455 |
'css' => 'default', |
|
456 |
), |
|
457 |
); |
|
458 |
|
|
459 |
// Merge default settings. |
|
460 |
$settings = $settings + $default_settings; |
|
461 |
|
|
443 | 462 |
$form['vote'] = array( |
444 | 463 |
'#type' => 'fivestar', |
445 | 464 |
'#stars' => $settings['stars'], |
446 |
'#auto_submit' => isset($settings['autosubmit']) ? $settings['autosubmit'] : TRUE,
|
|
465 |
'#auto_submit' => $settings['autosubmit'],
|
|
447 | 466 |
'#allow_clear' => $settings['allow_clear'], |
448 | 467 |
'#allow_revote' => $settings['allow_revote'], |
449 | 468 |
'#allow_ownvote' => $settings['allow_ownvote'], |
450 |
'#required' => isset($settings['required']) ? $settings['required'] : FALSE,
|
|
451 |
'#widget' => isset($settings['widget']) ? $settings['widget'] : array('name' => 'default', 'css' => 'default'),
|
|
469 |
'#required' => $settings['required'],
|
|
470 |
'#widget' => $settings['widget'],
|
|
452 | 471 |
'#values' => $values, |
453 | 472 |
'#settings' => $settings, |
454 | 473 |
'#description' => $settings['description'], |
... | ... | |
498 | 517 |
|
499 | 518 |
// We need to process the 'fivestar' element with the new values. |
500 | 519 |
$form['vote']['#values'] = $values; |
501 |
$new_element = fivestar_expand($form['vote']); |
|
520 |
// Also need to pass on form_state and the complete form, just like form_builder() does. |
|
521 |
$new_element = fivestar_expand($form['vote'], $form_state, $form_state['complete form']); |
|
502 | 522 |
// Update the description. Since it doesn't account of our cast vote above. |
503 | 523 |
// TODO: Look into all this, I honestly don't like it and it's a bit weird. |
504 | 524 |
$form['vote']['vote']['#description'] = isset($new_element['vote']['#description']) ? $new_element['vote']['#description'] : ''; |
... | ... | |
549 | 569 |
/** |
550 | 570 |
* Process callback for fivestar_element -- see fivestar_element() |
551 | 571 |
*/ |
552 |
function fivestar_expand($element) { |
|
572 |
function fivestar_expand($element, $form_state, $complete_form) {
|
|
553 | 573 |
if (!_fivestar_allow_vote($element)){ |
554 | 574 |
$element['#input'] = FALSE; |
555 | 575 |
} |
... | ... | |
562 | 582 |
$values = $element['#values']; |
563 | 583 |
$class[] = 'clearfix'; |
564 | 584 |
|
585 |
$title = 'it'; |
|
586 |
if (isset($element['#settings']['entity_id']) && isset($element['#settings']['entity_type'])) { |
|
587 |
$entity_id = $element['#settings']['entity_id']; |
|
588 |
$entity = entity_load($element['#settings']['entity_type'], array($entity_id)); |
|
589 |
$entity = $entity[$entity_id]; |
|
590 |
$title = $entity->title; |
|
591 |
} elseif (isset($complete_form['#node'])) { |
|
592 |
$title = $complete_form['#node']->title; |
|
593 |
} |
|
565 | 594 |
$options = array('-' => t('Select rating')); |
566 | 595 |
for ($i = 1; $i <= $element['#stars']; $i++) { |
567 | 596 |
$this_value = ceil($i * 100/$element['#stars']); |
568 |
$options[$this_value] = t('Give it @star/@count', array('@star' => $i, '@count' => $element['#stars']));
|
|
597 |
$options[$this_value] = t('Give @title @star/@count', array('@title' => $title, '@star' => $i, '@count' => $element['#stars']));
|
|
569 | 598 |
} |
570 | 599 |
// Display clear button only if enabled. |
571 | 600 |
if ($element['#allow_clear'] == TRUE) { |
Formats disponibles : Unified diff
Weekly update of contrib modules