Problem/Motivation
Report received & verified as reproducible at https://www.drupal.org/project/commerce_cart_redirection/issues/3496009
The Commerce Cart Redirection module allows the site admin to arbitrarily modify the text of the Add to cart button, this causes the add to cart button to lose its theming.
Thoughts
It seems that the class addition depends on the button text being "Add to Cart" fairly late in the rendering process.
In the Commerce Cart Redirection module, I modify the button text earlier in the workflow ( in a form_alter ), which results in the classes not being added as expected. I’ve implemented a workaround in the 3.3.x-dev version using string substitution on the rendered button markup in a post_render callback. It's functional but it's not a feel good solution and it may not be reliable.
Questions and Assistance Needed
- Is there a recommended way within the Belgrade theme to ensure classes are applied to the button regardless of text changes?
- Could this behaviour be decoupled from the button text, such as targeting the button via selectors or hooks?
- Are there any hooks or methods I could use to safely modify the button text without interfering with class additions?
I'd like to make the module work with the Belgrade theme while maintaining flexibility for sites that already use custom button text. Any insights or guidance you can provide would be greatly appreciated.
Thanks!
Issue fork belgrade-3496129
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
Comment #2
majmunbog commentedI can create a custom hook
belgrade_button_classesthat we could use to override the button classes like this:Comment #3
lavanyatalwar commentedComment #5
majmunbog commentedComment #6
majmunbog commentedComment #7
lavanyatalwar commentedComment #9
rszrama commentedComment #11
majmunbog commentedCode is merged. All seems to work well.
Comment #12
majmunbog commented