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.

Command icon 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:

Comments

ytsejam created an issue. See original summary.

agoradesign’s picture

makes sense

rhovland made their first commit to this issue’s fork.

rhovland’s picture

Version: 2.0.0-rc2 » 2.0.x-dev
Status: Active » Needs review

This 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.

rhovland changed the visibility of the branch 3556155-a-class-for to hidden.

rhovland’s picture

The 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-link as 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-link in the empty template too?

agoradesign’s picture

tough 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

rhovland’s picture

Oh 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?

  • rhovland committed 92c5c15b on 2.x
    Issue #3556155 by ytsejam, rhovland, agoradesign: Add a class and theme...

  • rhovland committed 9e70bc7d on 2.0.x
    Issue #3556155 by ytsejam, rhovland, agoradesign: Add a class and theme...

  • rhovland committed 346dce65 on 2.1.x
    Issue #3556155 by ytsejam, rhovland, agoradesign: Add a class and theme...
rhovland’s picture

Version: 2.0.x-dev » 2.x-dev
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.