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.
Instead of icons I see "1 Like 0 Dislike"
Comment | File | Size | Author |
---|---|---|---|
#15 | no_icons_shown-2765035-15-interdiff.txt | 9.66 KB | mbovan |
#15 | no_icons_shown-2765035-15.patch | 31.48 KB | mbovan |
| |||
#13 | no_icons_shown-2765035-13-interdiff.txt | 12.63 KB | mbovan |
#13 | no_icons_shown-2765035-13.patch | 27.88 KB | mbovan |
| |||
#11 | no_icons_shown-2765035-11-interdiff.txt | 3.21 KB | mbovan |
Comments
Comment #2
Bambell CreditAttribution: Bambell at MD Systems GmbH commentedWork in progress patch. Now adding the links from a template.
Comment #3
Bambell CreditAttribution: Bambell at MD Systems GmbH commentedI have ported the full "icon experience" from the Drupal 7 module. The text links are now icons. Clicking on those icons triggers an Ajax call to register the vote and refreshes the vote count. I did a bit more too and made it so the status/warning messages are also added via the Ajax call, which wasn't done in the Drupal 7 module. It's fully functional, but there still seems to be some caching issues that I can't figure out. If voting randomly multiple times, I've noticed that once in a while a vote doesn't get properly registered or canceled. It seems to appear randomly.
We also need to discuss how the icons should be displayed. Currently, we have red thumb down and up icons and gray thumb down and up icons. When voting, a css class is dynamically added to switch to the gray icons. However, when refreshing the page, the red icons are still displayed. Furthermore, right now, the gray icons are not clickable. This is not consistent with the fact that users can cancel their votes. Screenshot (2 is after Ajax call, 3 is after a page refresh) :
(sorry for the lack of Gimp skills)
I think what would make more sense would be to have a green thumb up icon, a red thumb down icon and somehow "highlighted" green thumb up and red thumb down icons. After voting, the "highlighted" icon is used for the choice that was chosen. The user can still click on either type of icon to cancel his vote. Any other suggestion?
Comment #4
BerdirI'm not a visual person, so I have no strong preference there.
I expect many sites will want to customize this anyway. So what's more important than the look is that will work well.
I'm also fine with a follow-up issue to change the icon color and behavior. in general, I like your idea. For highlighting, we could use filled and non-filled tokens. I think it should also only highlight the icon you actually clicked, to indicate your choice, not both. But again, lets get the functional part right first.
haven't seen that kind of wrapper before, no idea what it does :)
that seems misleading, that's not the status but wheter you can like or not. I'd name those _permission.
_status would then imho be whether the user did vote this, which should also solve the problem of not having the class after a refresh. could also be a single one that contains nothing, like or dislike as a string.
can we put the js files into a separate js folder?
usually jQuery/Drupal/drupalSettings are passed in and there is only a single wrapper. check core JS files in modules.
also, I think it is more common to register functions like this on Drupal and not on globally. e.g. Drupal.ajax.
we should ask someone who is more familiar with JS to review this.
this is not translatable like this, also, usually json is used to return data instead of custom encoded strings. should be easier to parse. (see JsonResponse)
use |t to translate this.
Comment #5
Bambell CreditAttribution: Bambell at MD Systems GmbH commentedI made most of these changes.
Yes, that's what I meant. I'll open a new issue to discuss and work on this.
I already did that, but we don't want the icons permanently disabled after voting, cause users can still cancel or change their vote. Maybe we can leave this like this for now (icons disabled after voting, enabled again after a refresh) and do this properly in the other issue?
Everything should be properly translatable now.
Also, the
click()
event was always called twice. I'm not exactly sure why. The Javascript is attached inlike_and_dislike_entity_view()
, which will likely be called multiple times. But, even in cases this function is called only once, theclick()
event was triggered twice. I fixed that by unbinding the click function from the anchor tag before binding it. This caused the glitchiness I observed earlier.Tokens?
Comment #6
Bambell CreditAttribution: Bambell at MD Systems GmbH commentedChanged this so that the icons are still clickable after voting and remain red. If we still want them clickable, I think it would make more sense not to turn them gray. So voting doesn't visually affect the icons now. The icons are only gray and unclickable if the user doesn't have permission to vote. Still need to discuss in #2773341: Proper look and behaviour for like and dislike icons. if we want the selected vote somehow "highlighted" / better visual feedback after voting.
Comment #7
Berdiras mentioned in the unlike issue, this is not valid, the full sentence needs to be translatable as a while, or it will not be possible to do it correctly in some languages. And as written there, not sure how much you already did there, it could be simplified to avoid "vote". that we use a voting api internally is an implementation detail.
I think that's just printing it out as a string ;)
You need something like {{ 'Book traversal links for'|t }}
Comment #8
Bambell CreditAttribution: Bambell at MD Systems GmbH commentedActually, what about just "Your vote was added." / "Your vote was canceled."?
Ha ! Never noticed it !
Comment #9
BerdirThe binary files are missing in the patch.
Comment #10
Stephen Ollman.like-and-dislike-container a {
width: 21px;
height: 21px;
text-indent: -9999px;
background: url("../images/icons.png") 0 0 no-repeat;
cursor: pointer;
}
Missing icons.png
Comment #11
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedAdded images.
Comment #13
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedHuh, test fixes...
Comment #14
BerdirPatch doesn't apply anymore but should be easy to resolve.
Also quite hard to review, so I'll just add some general notes.
* Quickly tests, basically works. lets get this in asap, but we'll need to work on #2773341: Proper look and behaviour for like and dislike icons. then for an acceptable user experience.
* I don't like the like_permission keys, lets make this like_access and dislike_access.
* the access check logic doesn't seem very reliable, it just depends on a class being there or not. maybe we could leave the JS/library out completely if the user doesn't have access, also a performance improvement. The controller should also again check access.
* resetCache()/reload of the entity seems overkill. just increment/decrement the property based on the action that happened. view builder reset is necessary.
* not all messages in JsonResponse are translatable.
Unrelated, for separate follow-up issues (possible student novice issues):
* No idea what LikeDislikeAccessController is for, doesn't seem to be used.
* multiple uses of entity (type) manager in controller, should be injected
Comment #15
mbovan CreditAttribution: mbovan at MD Systems GmbH commented#15 should be addressed with this patch. Sorry for long patch...
Will create followups soon.
Comment #17
BerdirThanks, I think this is a good first step, lets continue in the follow-up to improve the UI.
Comment #18
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedCreated follow-ups: #2800679: Inject entity managers/services through the module and #2800677: Remove like and dislike access controller