Closed (fixed)
Project:
Voting API
Version:
8.x-3.x-dev
Component:
Views Integration
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 May 2016 at 08:42 UTC
Updated:
23 Sep 2019 at 08:22 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ravi_sam commentedThe attached patch provides VoteResult views data and views relationship for nodes, users and comments views. With this, it is possible to display the total votes cast on these entities, in their respective views. Pls review.
Comment #3
recrit commentedComment #4
recrit commentedThe attached patch takes a more generic approach created views relationships for every content based entity type installed on the system. The patch in #2 provided node, comment, and user relationships and assumed all were installed on the system.
The following relationships are added for each entity type, votingapi result function (average, sum, count), and vote type (up, down, ...):
Comment #5
recrit commentedPatch update - added back base table definition per patch #2.
Comment #6
malcomio commentedWith the patch from #5 applied, I tried to create a "Most popular" view on a site with the current state of core's 8.2.x branch.
I observed two issues:
Drupal\Core\Config\ConfigValueException: node_vote_result_vote_field_average:node.field_rating key contains a dot which is not supported. in Drupal\Core\Config\ConfigBase->validateKeys()The second issue seems to be related to #2780869: Cannot save a view where a filter value option contains a period
Comment #7
rbrandon commentedI updated the patch from #5, I was able to remove some duplicate code and fixed both issues mentioned in #6.
The fatal error was easy to overcome by not using the period in the views handler key. There were not many duplicates, there is one relationship added for each field type and for each vote type, so the product is a little large and confusing. For the fields I added the field name into the label so that you can understand what relationship you are targeting.
Comment #8
kpv commentedSupport for entity types other than content would also be great to have.
I'm using a contact form together with Contact storage to collect user reviews. After that those reviews can be rated. Since it's neither a content entity nor translatable, a relationship doesn't appear in Views.
Here is the code from #5 with the check:
Comment #9
betz commentedSomeone made any progress on views integration?
Comment #10
grinder3011 commentedI just recently had the need of relationships for Voting API and tested the votingapi-views-relationships-for-vote-result-2731101-7.patch which works fine for me.
Therefor to the developers and maintainers of Voting API, I also ask if you can include the patch so that those who come here for the same reason don't need to go through patching needlessly.
Comment #11
malcomio commentedSetting status back to "Needs review" so that testbots and maintainers will see this issue (see https://www.drupal.org/node/156119 for more info on status)
Comment #12
codeyourdream commentedWe have updated the patch from #7 with the ability to sort the views by voting result. If an entity has no votes, it will be sorted to between entities with positive and negative results (as if it's result is 0).
Comment #13
maaty388 commentedWhat about in search_api views I cannot see vote relationships?
Comment #14
maaty388 commentedI'm getting error on page
Comment #15
sylus commentedJust adding this patch as a quick workaround so am not getting issues with search api views.
Comment #16
sylus commentedJust adding this patch with a better workaround so am not getting issues with search api views and others.
Comment #17
blazey commentedAttached patch is based on the one from #16. It removes the piece of code mentioned in #8, so the views integration works with contact messages.
Comment #18
blazey commentedThe patch from #17 was broken, attaching the proper one.
Comment #19
duneblMaybe I missed something, but I have tried several patches : #7, #16 and #18... none of them could solve my sort problem.
Drupal 8.4-dev
votingapi 8.3.x-dev
I have created a content type (node) with a voting field:
Vote plugin: 5 stars rating
Vote type: Normal vote (default)=>points
Number of allowed values: 1
And a view to list this content type (no relationship).
I have tried several combination of the field: read-only (yes/no), show result (yes/no), Show own vote (yes/no) without success
Comment #20
pifagorPlease test. I recreated patch, but I didn't test it.
Comment #21
pifagorComment #23
pifagorComment #24
alesbencina commentedI have added relationship but sorting not really working.
Comment #25
pifagorcan you write all the dependencies and step-by-step instruction to reproduce the problem?
Comment #26
alesbencina commentedI have tested the last patch with a combination of votingapi widgets module (dev version), which populates tables votingapi_results and votingapi_vote correctly. Or maybe should I go through all these patches and apply them 1 by 1?
Comment #27
drupalgin commentedMaybe, you have to test on the version 8.x-3.x-dev of the module?
Comment #28
alesbencina commented@drupalgin I test on Voting API 8.x-3.x-dev.
Comment #29
alesbencina commentedHello, to apply vote relationships on a view you can use this patch. It's from patch #7.
When adding a relationship you have to select "Vote Result "Average" for content items: Normal vote" or other if you are working with votingapi_widgets module.
If you want to sort ASC or DESC you have to select Vote result: Value and set sort order to top (it have to be first).
Please test it.
Comment #30
labboy0276 commentedThe patch in #29 correctly solves the issue of implementing a relationship + view fields. I tested it out and it works as stated.
Comment #32
pifagorComment #34
dchakrab commentedAlso tested patch in #29, can verify that it's working. Can we have this rolled back into the module?
Comment #35
markwittens commentedI have also installed and tested patch #29 successfully.