Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Entity Reference will, in time, replace the references module.
So it would be great if fivestar could support it.
Comment | File | Size | Author |
---|---|---|---|
#20 | Contact teacher2 Mudarrisi.png | 347.22 KB | murtza |
#15 | entityreference-support-1488914-15.patch | 1.98 KB | cafuego |
#8 | Screen Shot 2012-04-17 at 10.14.36 PM.png | 24.83 KB | nafmarcus |
#6 | fivestar-support_entityreference_1488914-6.patch | 1.75 KB | CmKeen |
Comments
Comment #1
ericduran CreditAttribution: ericduran commentedAgree, should be rather easy to write.
Comment #2
CmKeen CreditAttribution: CmKeen commentedI have exactly the same need.
If someone could guide me, I'm willing to try to patch this one.
Comment #3
CmKeen CreditAttribution: CmKeen commentedI made some tests and I managed to link the rating field from my review content type to the main content type.
However, whenever I create a new review with a rating, the rating field on the main content type gets the new value and don't add the different votes. I don't really know what I did wrong. Maybe someone can help review my changes.
Here there are:
Here is the place where I add the entityreference link
And here is the callback function
Comment #4
CmKeen CreditAttribution: CmKeen commentedOK, now I know.
In fact it works as planned. The last rating of a specific user overwrite the previous one; but if another user creates a new rating, it works flawlessly.
So, my modification works perfectly.
Can someone help me to create a real patch of it?
Tx.
Comment #5
Shadlington CreditAttribution: Shadlington commentedIf you have git installed its really easy, see: http://drupal.org/node/707484
Comment #6
CmKeen CreditAttribution: CmKeen commentedHere is the patch.
Hope I got it right
Comment #7
nafmarcus CreditAttribution: nafmarcus commentedOne first attempt, looks good. Thanks so much!
Comment #8
nafmarcus CreditAttribution: nafmarcus commentedI altered the registration form and added my own form with field of type fivestar.....
$form['review_overall_rating'] = array(
'#type' => 'fivestar',
'#title' => t('General rating'),
'#required' => TRUE,
'#stars' => 5,
'#weight' => -45,
);
After the user clicks "Register", I create a node and copy the rating field
function gitb_reviews_user_insert(&$edit, $account, $category) {
Create $node object.
...assign some fields
$node->field_overall_rating['und']['0']['rating'] = $edit['review_overall_rating'];
....assign some more fields
call node_save($node)
}
I receive the following error (see attached file):
"Notice: Undefined index: target_id in fivestar_target_entityreference() (line 804 of /User/..../contrib/fivestar/fivestar.module)
I don't quite understand the fivestar module well enough to know if this is related to supporting entityreference but it seems like it might be.
Comment #9
Energyblazar CreditAttribution: Energyblazar commentedThank you this is very close to the solution am looking for in my project. The patch is working perfectly when i am using references module and fivestar along with this patch.
Comment #10
Energyblazar CreditAttribution: Energyblazar commentedCan any one tell me why there is no data being added to field target. Why is it always null in the database, what am i missing or doing wrong ?
Comment #11
ericduran CreditAttribution: ericduran commentedLooks like it needs work based on everyones comments above.
The isset is checking for the key of 0, yet the is_numeric checks the target_id. The is_numeric is going to throw a notice if target_id isn't set which is what it should be checking in the isset before. Which I'm guessing is also the problem with the comment in #8.
Comment #12
nafmarcus CreditAttribution: nafmarcus commentedAt least part of the error was mine. I had not initialized the entity reference correctly in the node.
Comment #13
polosatique CreditAttribution: polosatique commentedIn your code you set target to node:
$target['entity_type'] = 'node';
But entity could not be only 'node', I'm using Entity Reference module to set reference to user. Is it possible set a real entity type which I referenced to?
Comment #14
lupus78 CreditAttribution: lupus78 commentedI made a quick test, and it seams to me that the target_id field is also NULL if you use node_reference module. The vote is stored right in the votingapi_vote table.
Comment #15
cafuego CreditAttribution: cafuego commentedAttached patch contains all changes from #6 by CmKeen and has an extra data check to avoid the warning seen by nafmarcus in #8.
Additionally, the
_fivestar_target_entityreference()
callback now loads the targeted entity type information so the correct entity type is stored with the vote in the votingapi_vote table.Please test! :-)
Comment #16
LeviThomason CreditAttribution: LeviThomason commentedFirst - very grateful to all working to bring entity reference support to fivestar :)
Now the issue... In short, after patch in #15 voting target apparently does not receive votes. In detail,
Setup:
- Drupal 7.18
- Entity Reference 7.x-1.0
- Fivestar7.x-2.0-alpha2+5-dev (+#15 patch)
- Voting API 7.x-2.10
Workflow:
1) Created "Explanation" content type
2) Created "Explanation Peer Review" content type with ER field "field_explanation_review_parent" to "Explanation" bundle
3) For both content types: Added fivestar field "Evidential", (vote while editing), tag "explanation_evidential"
4) Applied #15 patch and am now given "Voting target" option on fivestar field settings which displays my entity reference field
5) Selected the only ER field I created
Results:
- "Explanation" (parent entity) fivestar field shows 0 votes
- Target column in table "field_data_field_evidential" is NULL
I have tried typical end user troubleshooting: re-patching and starting over, deleting and recreating the ER field and fivestar fields, clearing cache, attempted w/wo Entityreference prepopulate enabled on ER field.
I apologize I do not have the necessary coding experience to shed more light or possible solutions on the issue.
Thanks again!
Levi
Comment #17
cafuego CreditAttribution: cafuego commentedHmm, on my install (only referencing nodes) the votes all end up in the {votingapi_vote} table and I can access those votes via Views. Can you check if there is anything in that table on your install? When you view the content with the vote, are stars or a percentage rendered ok?
Comment #18
LeviThomason CreditAttribution: LeviThomason commentedYou are correct, voting on the child node correctly stores the vote data in the {votingapi_vote} table with the parent NID. This is accessible through views as well. When viewing the child content the fivestar field is rendered correctly also.
However, I find no way to display the Voting API voting results using fivestar? The target column in the fivestar table still shows NULL. Is this by design?
Below deviates from the original issue, please let me know if/where I should move it.
My goal was to achieve the same effect as described in the documentation here Fivestar 7.x: Creating a User Comment/Rating and Average Rating for a Content type except using my own custom review content type instead of comments. In this tutorial, comments and their node parent shared the same fivestar field as well as the same field data. This allowed me to configure the comments to show "user's vote" and the node to show "average vote". When votes were cast via comments, both the comment and the parent could display the data using fivestar, very cool. This does not seem possible when retrieving data from {votingapi_vote} through views.
Your comment did inspire a solution which produces the same result as the tutorial above, except using views and panels. Hopefully this helps others too:
This view could be used without panels on any fieldable parent entity using Entity Views Attachment (EVA). If you do this, I believe you will need to provide the contextual filter with a default value: Content ID from URL.
Since the vote data is taken directly from the child node, the fivestar field does not need to exist on the parent entity nor does the fivestar field need to have a voting target. The downside I see here is that the parent's total average vote will not be available to other modules (such as rules) as it is not stored but calculated at run-time.
update
Although the fivestar formatters render correctly using this view, the text under the stars will read incorrectly :(
Comment #19
apdp300 CreditAttribution: apdp300 commentedHi, Thanks for the great module.
I have an issue. I create content type A with fivestar field tag vote1 set to display average vote, rate while viewing, exposed no. I create content type B with entity reference to a type A and fivestar field tag vote1 target of voting the entity reference to type A, rate while editing, display users vote. This works fine and the average vote is shown on type A when several pieces of content type B are added.
However then I add another fivestar field to type B, tag vote2, rate while viewing, exposed yes. But when a user votes on vote2, the scores in fivestar field with tag vote1 on type B are nulled which also effects the average displayed on type A.
All help appreciated. Thanks very much.
Adam
Comment #20
murtza CreditAttribution: murtza commentedI want to rate user entity so i have created a fivestar rating field (rated while viewing and display the average rating) in user account fields and i have created a content type "review" and in this content type i have added a fivestar field (rated while editing) and voting target is user entity. i have added three reviews for a user and when i see the user profile, there is no average instead user profile i can see the rating of latest review but i want to display the average rating here. How can i do it.
Comment #21
chris_h CreditAttribution: chris_h commentedThis works really well for me. It's crucial functionality that should be in the dev release.
Comment #22
kmadel CreditAttribution: kmadel commentedI've tested with the latest dev branch of fivestar and:
Hopefully this can move forward and be added to the 7.x-2.x dev branch. Especially considering that Entity Reference is in Drupal 8 core and is really the path to the future in regards to referencing between entities and bundles.
Comment #23
jibize CreditAttribution: jibize commentedPatch from #15 works great, thank you cafuego.
I would definitely love to see this patch getting in as well.
Comment #24
Pierre_G CreditAttribution: Pierre_G commentedPatch from #15 works perfectly. Thanks !
Maybe we can apply it to the dev now ?
A few months have past and it is really crucial.
Comment #25
whiteph CreditAttribution: whiteph commentedI've just committed the patch in #15. Thanks @cafuego and everyone who has worked on this.
Comment #26
dobe CreditAttribution: dobe commentedI am using the latest Dev version.
I have done everything similar to #16's comment.
I have a product and a review content type, all my reviews have references to the products. The field has the setting for the entity reference field that references the product on the Review content type.
The product rating does not get updated. I have saved, resaved, created new reviews but it does not seem to update the fivestar rating on the product page. In the database the review rating target does not change from NULL. I have also set the appropriate target id in one of them just to test and it doesn't effect anything.
Any ideas on this issue are much appreciated.
-Jesse
Comment #27
whiteph CreditAttribution: whiteph commentedComment #28
shi99 CreditAttribution: shi99 commentedLike mentioned in #26 I am also having trouble with the parent node (Product) showing an average of all reviews.
I followed the steps but no luck.
Any advice would be great.
Comment #29
shi99 CreditAttribution: shi99 commentedA quick follow up to #28.
I noticed if I set the fivestar field in parent node (Product) to use the widget "Stars (rated while viewing)" (this is system option know as "exposed"), the average is calculated on the product page. But using this option allows people to vote when viewing the product and I only want them to vote via the review content type.
Is there some option I am missing?
Comment #30
shi99 CreditAttribution: shi99 commentedI found out what I was doing wrong.
Just going to explain what I did in case somebody else is having the same issue.
In the parent content type (E.g Product) add the Fivestar field and set the widget to "Stars (rated while viewing)"
Then in the display mode for the Fivestar field uncheck the checkbox "Allow voting on the entity."
This then will calculate the averages from the review content type but make them not editable when viewing the Product page.
You can see steps here https://drupal.org/node/1308114
Even though it's about nodes with using comments for reviews, the first section "Setting up the Content Type (node)" uses the same process with using nodes and entity references for reviews.
Comment #31
whiteph CreditAttribution: whiteph commentedFollowing on from @shi99 feedback in #28, #29, and #30, it seems that this can now be closed. To get average votes in the entity and user votes in comments, it's key to follow exactly every step in Fivestar 7.x: Creating a User Comment/Rating and Average Rating for a Content type
If anybody disagrees, please reopen this issue and give a detailed description of the problem.