1
我使用fivestar 1.19和投票軸。我相信默認的五星級區塊/五星級功能只使用默認的「投票」標籤。Drupal:具有投票軸的Fivestar Block
fivestar_widget_form($節點)
我需要我的自定義標籤的五星傳遞給函數。
試圖按照下面的答案: 對我而言,$ object是$ node。
<?php
function custom_fivestar_widget ($object) {
global $user;
$star_display = variable_get('fivestar_style_'. $object->type, 'average');
$text_display = variable_get('fivestar_text_'. $object->type, 'dual');
if ($star_display == 'average' && ($text_display == 'average' || $text_display == 'none')) {
// Save a query and don't retrieve the user vote unnecessarily.
$votes = fivestar_get_votes($object->type, $object->nid, 'score', 0);
}
else {
$votes = fivestar_get_votes($object->type, $object->nid);
}
$values = array(
'user' => isset($votes['user']['value']) ? $votes['user']['value'] : 0,
'average' => isset($votes['average']['value']) ? $votes['average']['value'] : 0,
'count' => isset($votes['count']['value']) ? $votes['count']['value'] : 0,
);
$settings = array(
'stars' => variable_get('fivestar_stars_'. $object->type, 10),
'allow_clear' => variable_get('fivestar_unvote_'. $object->type, FALSE),
'style' => $star_display,
'text' => $text_display,
'content_type' => $object->type,
'content_id' => $object->nid,
'tag' => 'score',
'autosubmit' => TRUE,
'title' => variable_get('fivestar_title_'. $object->type, 1) ? NULL : FALSE,
'feedback_enable' => variable_get('fivestar_feedback_'. $object->type, 1),
'labels_enable' => variable_get('fivestar_labels_enable_'. $object->type, 1),
'labels' => variable_get('fivestar_labels_'. $object->type, array()),
);
return fivestar_custom_widget($form_state, $values, $settings);
}
print drupal_get_form('custom_fivestar_widget', $object);
?>
這給我打印小部件,我相信使用我的分數。然而,文字顯示全都是錯誤的,正如平均分數一樣。它給所有東西一個永久的10顆星。 :(
感謝您的幫助。我沒有能夠得到這個工作,我編輯了我的問題與我的嘗試。 – Jourkey
啊,忘了: 創建您的代碼的功能,並在此調用方式: 打印drupal_get_form('yourformfunction',$對象等變量); 我認爲,也主題五星形式將有用... – Nikit
對不起......我不知道你的意思。你請請更具體。我完全迷失了,特別是在你放置變量的地方。在函數和drupal獲取表單中,我需要什麼params。也可以更換content_type和id,我想他們可能不是我認爲他們的意思。謝謝。 content_type是內容的類型,還是它的用戶/節點/等等。我很迷茫,請幫忙。謝謝! – Jourkey