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.
Drupal core prefixes classes needed to provide Javascript funtionality wir 'js-'. Commerce should do so as well to indicate which classes can be removed and which are required. One example in commerce_cart:
Current
commerce_cart.module:
<?php
/**
* Prepares variables for the cart block element template.
*/
function template_preprocess_commerce_cart_block(&$variables) {
$variables['attributes']['class'][] = 'cart--cart-block';
}
?>
commerce_cart.js:
var $cart = $context.find('.cart--cart-block');
Should be
commerce_cart.module:
<?php
/**
* Prepares variables for the cart block element template.
*/
function template_preprocess_commerce_cart_block(&$variables) {
$variables['attributes']['class'][] = 'js-cart--cart-block';
}
?>
commerce_cart.js:
var $cart = $context.find('.js-cart--cart-block');
Comment | File | Size | Author |
---|---|---|---|
#3 | prefix_classes_needed-2877358-3.patch | 7.26 KB | gauravjeet |
Comments
Comment #2
Lukas von BlarerComment #3
gauravjeet CreditAttribution: gauravjeet as a volunteer and at Acro Commerce commentedHave prefixed class names with 'js-'. Only those class names been changed that are being added into Library via #attributes.
https://github.com/drupalcommerce/commerce/pull/743
Comment #4
Thomas CysGreat work but in my opinion .js-* classes should only be used to denote behaviour.
Comment #5
Lukas von BlarerWhat do you mean by behavior?
The "js-" class prefixing is there to indicate that removing it might break javascript, right?
Comment #6
Thomas CysWhat i mean is that you shouldn't style "js-" prefixed classes.
Comment #7
Lukas von BlarerOk, then we agree that all classes required by javascript should be prefixed?
Comment #8
Thomas CysOfcourse but they shouldn't have css attached to them.
Comment #9
Lukas von BlarerYes, for that separate classes are needed. I guess we leave the existing ones in place and duplicate them with the js- prefix?
Comment #10
Lukas von BlarerIs it too late to get this in before a stable release?
Comment #11
bojanz CreditAttribution: bojanz at Centarro commentedIt can still happen.
Comment #12
Lukas von BlarerThe patch is looking good so far. I encountered a few occurances of the .cart class:
CartBlock.php:
CartController.php:
I guess those are not needed by JS, but they are kind of hard to get rid of. Can we solve this differently?
Comment #13
Lukas von BlarerBut actually this is a different issue. We should move that HTML to templates. I created an issue for that: #2900616: Move HTML to twig templates