Hi, how may I edit the star labels for fivestar cck fields?

Thanks!

Comments

quicksketch’s picture

Currently you cannot edit the labels for Fivestar CCK fields through the UI. You can implement a hook_form_alter() in a custom module to change it manually.

Flying Drupalist’s picture

Category: support » feature

Thank you quicksketch. I'll go do that. :)

jazzdrive3’s picture

Version: 6.x-1.x-dev » 5.x-1.13

I'm needing the same thing. Is there a quick tutorial on how to do this?

Changing the labels on cck fields is pretty important for the advanced reviews I'm doing.

jazzdrive3’s picture

Or can you just let me know where in the code I can hard code the changes I want. They will be the same sitewide. Which file is this info in?

Thanks!

japanitrat’s picture

Version: 5.x-1.13 » 6.x-1.13
StatusFileSize
new4.27 KB

Check this patch out for the D6 version (you need to go to the field settings and save them to 'enable' the labels for a certain field)

japanitrat’s picture

Status: Active » Needs review
Flying Drupalist’s picture

Hmm, can someone commit this please?

jazzdrive3’s picture

Yes please. I can never get patches to work.

bomarmonk’s picture

StatusFileSize
new3.31 KB

This patch worked rather nicely, except that it doesn't work with fivestar and the nodereview module (there is a 6.x version posted in the issue ques). It would be great if the fivestar labels could be used by the nodereview axis settings. Any possibility of hooking into nodereview with this patch? Or does nodereview need to hook into this new feature for fivestar? I'm attaching a patched version of fivestar_field.inc for those who want to test but have difficulty applying patches.

Anonymous’s picture

There seems to be a bug on line 259 of the patched file (line 90 in the original patch):

for($i=0; $i < $stars; $i++) $labels[] = $field['label_'.$i];
should be:
for($i=0; $i <= $stars; $i++) $labels[] = $field['label_'.$i];

The bug results in the label of the last star always being set to a default value.
Can anyone out there confirm or deny my suspicions?

talatnat’s picture

Confirm that the last star gets set to the default value if the labels are changed (remains at 'Give it 3/3' for a three-star widget), and also confirm that the fix proposed solves this. (I used the zip file.)

This works fine on the Fivestar CCK field of a certain content-type form. However, after the node is published, hovering on the stars does not display the star labels. So, if one's labels are Poor, Good, Best for three stars, then a 2-star rating does not display Good on mouseover. Can someone confirm this? If not, can we add this to the Feature Request?

ManyNancy’s picture

Version: 6.x-1.13 » 6.x-1.19
shawn dearmond’s picture

Here's how to use hook_form_alter() to add the labels to your form:

<?php
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'mynodetype_node_form') {
    $form['field_myfivestarcckfieldname'][0]['rating']['#labels_enable'] = TRUE;
    $form['field_myfivestarcckfieldname'][0]['rating']['#labels'] = array('label-for-cancel', 'label-for-1', 'label-for-2', 'label-for-3', 'label-for-4', 'label-for-5');
  }
}
?>
halloffame’s picture

How do you implement this with the default fivestar that comes along with the content type? I can't seem to find the field name of it. What would be its field name?

I know I can just edit the label via the content type ui but I'm looking to add a div class or a class around the labels. This would probably be the best way to do that.

theodorosploumis’s picture

StatusFileSize
new3.45 KB

This is a fixed "fivestar_field.inc" for version 6.x-1.19, also tested for 6.x-1.x-dev.

Some changes have been done in the code after the patch from http://drupal.org/node/333059#comment-1160475 applied (this patch was for 1.13 version).

You should replace your existing file at modules/fivestar/fivestar_field.inc with this one in order to have custom labels for fivestar.

Notice that if you set the "Number of Stars:" option, for example, at 4 you can only edit 4 custom labels and any other change on a label will not be saved!

Thanks for the patch japanitrat!

ericduran’s picture

Status: Needs review » Needs work

It looks like this patch need to be rerolled.

chinita7’s picture

Thanks for committing this patch. It works great ! The only thing is that Is it possible also to display the label on the node viewing page? Because the labels are showed only on node editing page. It will be wonderful if I can display the stars with respecting label next to them.For example if 2 stars are labeled as 'good', then on the node viewing page the stars(2 of them) are showed with the label 'good'
Is this possible?

whiteph’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Sorry, Drupal 6 is end of life, and is no longer supported.