I am trying to style the "Add the first review" link which displays in the product content after enabling the "Overall rating" field in /admin/commerce/config/product-types/default/edit/display, but it is the only one generated by this module that has no CSS class and the only way to manipulate it is with a complex selector which for some reason does not work on mobile phones.
Tried looking around the module code to find where it is being generated, but failed miserably, sorry.
If there was a dedicated CSS class for the "Add the first review" link, it would make my life so much easier. Thanks in advance.
Issue fork commerce_product_review-3556155
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3556155-theme-empty-link
changes, plain diff MR !36
- 3556155-a-class-for
compare
Comments
Comment #2
agoradesign commentedmakes sense
Comment #4
rhovlandThis is definitely an oversight and something that should have gone into the 2.0.0 release so even though it's a feature request it won't wait for 2.1.0.
I added a class to the link and created a template so this can be themed like the non-empty field can be.
Comment #7
rhovlandThe one dangling question I have is should the template have a div container in it and if so, what should the class be? In OverallRatingStarsFormatter we have
review-form-linkas the container for the link to write a review. In OverallRatingDefaultFormatter there is no link to write a review, just the link to the reviews page.Does it make sense to make the container class be
review-form-linkin the empty template too?Comment #8
agoradesign commentedtough question... adding the div is a potential layout-breaking change, that definitely needs to be addressed in the release notes.
If you think, this is the better solution, go ahead and add the wrapper. It can be easily replaced via Twig template override. People just need to be informed about that change
But, if you use the div, I'd rather go for {{ attributes.addClass('review-form-link') }} instead of directly writing class="review-form-link". this way, we're even more flexible. People can change/add attributes in preprocessors, without tpl override
Comment #9
rhovlandOh I had always wondered about why templates used attributes.addClass() but never dug into it. Makes sense.
I'm of two minds on the div too because on one hand normally fields are wrapped in something when displayed. Since this template is adding a placeholder for an empty field it should be in the same wrapper. However the field wrapper isn't added automatically in this situation. Any choice of wrapper I add is going to be wrong because it won't match whatever the site is using for the field wrapper template. So maybe I should leave the wrapping div out?
Comment #13
rhovland