function fivestar_custom_widget in Fivestar 5
Same name and namespace in other branches
- 6.2 fivestar.module \fivestar_custom_widget()
- 6 fivestar.module \fivestar_custom_widget()
- 7.2 fivestar.module \fivestar_custom_widget()
1 call to fivestar_custom_widget()
- fivestar_form in ./
fivestar.module - Create the fivestar form for the current item. Note that this is not an implementation of hook_form(). We should probably change the function to reflect that.
2 string references to 'fivestar_custom_widget'
File
- ./
fivestar.module, line 1098 - A simple n-star voting widget, usable in other forms.
Code
function fivestar_custom_widget($values, $settings) {
$form = array(
'#attributes' => array(
'class' => 'fivestar-widget',
),
'#base' => 'fivestar_form',
'#redirect' => FALSE,
'#theme' => 'fivestar_widget',
);
if (isset($settings['content_type'])) {
$form['content_type'] = array(
'#type' => 'hidden',
'#value' => $settings['content_type'],
'#id' => $settings['content_id'] ? 'edit-content-type-' . $settings['content_id'] : NULL,
);
}
if (isset($settings['content_id'])) {
$form['content_id'] = array(
'#type' => 'hidden',
'#value' => $settings['content_id'],
'#id' => $settings['content_id'] ? 'edit-content-id-' . $settings['content_id'] : NULL,
);
}
$form['vote'] = array(
'#type' => 'fivestar',
'#stars' => $settings['stars'],
'#vote_count' => $values['count'],
'#vote_average' => $values['average'],
'#auto_submit' => isset($settings['autosubmit']) ? $settings['autosubmit'] : TRUE,
'#auto_submit_path' => !isset($settings['autosubmit']) || $settings['autosubmit'] ? 'fivestar/vote/' . $settings['content_type'] . '/' . $settings['content_id'] . '/' . $settings['tag'] : NULL,
'#allow_clear' => $settings['allow_clear'],
'#content_id' => isset($settings['content_id']) ? $settings['content_id'] : NULL,
'#required' => isset($settings['required']) ? $settings['required'] : FALSE,
'#feedback_enable' => isset($settings['feedback_enable']) ? $settings['feedback_enable'] : TRUE,
'#labels_enable' => isset($settings['labels_enable']) ? $settings['labels_enable'] : TRUE,
'#labels' => isset($settings['labels']) ? $settings['labels'] : NULL,
'#tag' => isset($settings['tag']) ? $settings['tag'] : 'vote',
);
$form['destination'] = array(
'#type' => 'hidden',
'#value' => $_GET['q'],
'#id' => isset($settings['content_id']) ? 'edit-destination-' . $settings['content_id'] : NULL,
);
$form['fivestar_submit'] = array(
'#type' => 'submit',
'#value' => t('Rate'),
'#attributes' => array(
'class' => 'fivestar-submit',
),
'#id' => isset($settings['content_id']) ? 'edit-fivestar-submit-' . $settings['content_id'] : NULL,
);
$form['vote']['#attributes']['class'] = isset($form['vote']['#attributes']['class']) ? $form['vote']['#attributes']['class'] : '';
$settings['feedback_enable'] = isset($settings['feedback_enable']) ? $settings['feedback_enable'] : TRUE;
switch ($settings['text']) {
case 'user':
$form['vote']['#description'] = theme('fivestar_summary', $values['user'], NULL, $settings['style'] == 'dual' ? NULL : $values['count'], $settings['stars'], $settings['feedback_enable']);
$form['vote']['#attributes']['class'] .= ' fivestar-user-text';
break;
case 'average':
$form['vote']['#description'] = $settings['style'] == 'dual' ? NULL : theme('fivestar_summary', NULL, $values['average'], $values['count'], $settings['stars'], $settings['feedback_enable']);
$form['vote']['#attributes']['class'] .= ' fivestar-average-text';
break;
case 'smart':
$form['vote']['#description'] = $settings['style'] == 'dual' && !$values['user'] ? NULL : theme('fivestar_summary', $values['user'], $values['user'] ? NULL : $values['average'], $settings['style'] == 'dual' ? NULL : $values['count'], $settings['stars'], $settings['feedback_enable']);
$form['vote']['#attributes']['class'] .= ' fivestar-smart-text ' . ($values['user'] ? 'fivestar-user-text' : 'fivestar-average-text');
break;
case 'dual':
$form['vote']['#description'] = theme('fivestar_summary', $values['user'], $settings['style'] == 'dual' ? NULL : $values['average'], $settings['style'] == 'dual' ? NULL : $values['count'], $settings['stars'], $settings['feedback_enable']);
$form['vote']['#attributes']['class'] .= ' fivestar-combo-text';
break;
}
switch ($settings['style']) {
case 'average':
$form['vote']['#title'] = t('Average');
$form['vote']['#default_value'] = $values['average'];
$form['vote']['#attributes']['class'] .= ' fivestar-average-stars';
break;
case 'user':
$form['vote']['#title'] = t('Your rating');
$form['vote']['#default_value'] = $values['user'];
$form['vote']['#attributes']['class'] .= ' fivestar-user-stars';
break;
case 'smart':
$form['vote']['#title'] = $values['user'] ? t('Your rating') : t('Average');
$form['vote']['#default_value'] = $values['user'] ? $values['user'] : $values['average'];
$form['vote']['#attributes']['class'] .= ' fivestar-smart-stars ' . ($values['user'] ? 'fivestar-user-stars' : 'fivestar-average-stars');
break;
case 'dual':
$form['vote']['#title'] = t('Your rating');
$form['vote']['#default_value'] = $values['user'];
$form['vote']['#attributes']['class'] .= ' fivestar-combo-stars';
$form['#attributes']['class'] .= ' fivestar-combo-stars';
$static_average = theme('fivestar_static', $values['average'], $settings['stars'], $settings['tag']);
if ($settings['text'] == 'none' && !$settings['labels_enable'] && !$settings['feedback_enable']) {
$static_description = NULL;
}
elseif ($settings['text'] != 'none') {
$static_description = theme('fivestar_summary', NULL, $settings['text'] == 'user' ? NULL : (isset($values['average']) ? $values['average'] : 0), isset($values['count']) ? $values['count'] : 0, $settings['stars'], FALSE);
}
else {
$static_description = ' ';
}
$form['average'] = array(
'#type' => 'markup',
'#value' => theme('fivestar_static_element', $static_average, $settings['title'] !== FALSE ? t('Average') : NULL, $static_description),
'#weight' => -1,
);
break;
}
// Set an over-ridding title if passed in.
// An empty title won't change the default, a string will set a new title,
// and title === FALSE will unset the title entirely.
if (isset($settings['title'])) {
if ($settings['title'] !== FALSE) {
$form['vote']['#title'] = $settings['title'];
}
else {
unset($form['vote']['#title']);
unset($form['average']['#title']);
}
}
return $form;
}