Follow-up to #2849954: Double underscores are not preserved in main views CSS classes defined in views UI

Problem/Motivation

If set "my__class" value via Views UI (Edit View > Advanced > CSS) this will give two classes at the html-output:

my__class
my--class

Proposed resolution

Remove the BC layer
Provide a Change record with instructions how to restore the BC classes if they are needed

Issue fork drupal-2977950

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

Anonymous’s picture

vaplas created an issue. See original summary.

Anonymous’s picture

Title: [PP-1] Decide what to do with double views css classes » Decide what to do with the BC css class from the Views UI
Priority: Normal » Minor

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

lendude’s picture

Version: 8.9.x-dev » 9.0.x-dev
Issue tags: +D9 readiness

As predicted, this got lost along the way :) Tagging for D9 readiness

xjm’s picture

Version: 9.0.x-dev » 9.1.x-dev
Priority: Minor » Normal
kristen pol’s picture

Issue tags: -D9 readiness

"D9 readiness" isn't an "official" tag. Since this is marked for 9.1, I'm not sure a tag is needed. If it is, it should be "Drupal 9 readiness". Leaving off the tag for now.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lendude’s picture

This still being in, is now leading to people opening bugs #3391465: Views CSS class is changed when underscores and dashes are mixed, lets see if we can get rid of this

lendude’s picture

Status: Active » Needs review

So this just removes the BC layer. I don't see any way to detect that people are using these classes, all we can detect is if we are suppling them with BC classes, so raising a deprecation notice feel weird since it might not be relevant at all.

Would it maybe be sufficient to add a CR with a code snippet that could recreate the BC classes if somebody still needs them?

Something like this seems to do the trick:

function mytheme_preprocess_views_view(&$variables) {
  if (!empty($variables['attributes']['class'])) {
    $bc_classes = preg_replace('/[^a-zA-Z0-9- ]/', '-', $variables['attributes']['class']);
    $variables['attributes']['class'] = array_merge($variables['attributes']['class'], $bc_classes);
  }
  if (!empty($variables['css_class'])) {
    $existing_classes = explode(' ', $variables['css_class']);
    $bc_classes = preg_replace('/[^a-zA-Z0-9- ]/', '-', $existing_classes);
    $variables['css_class'] = implode(' ', array_merge($existing_classes, $bc_classes));
  }
}
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Could the issue summary be updated with the proposed solution, "Leave two classes as is." doesn't seem correct anymore.

And you're right not sure how to BC a class removal, and not the first ticket I've seen around this. A CR may be the best thing but even then I imagine if someone is using those removed classes they'll notice when something breaks before the CR.

lendude’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update

Updated the IS with the new proposal on how to address this.

I'll ping somebody to see if we can get some more opinions on how to deal with HTML class removal.

smustgrave’s picture

Whatever is decided should post here too #2413847: Remove usages of .js class from core

lauriii’s picture

Can we move the BC class to Stable 9? That's the standard approach and allows us to get rid of it once we replace Stable 9.

smustgrave’s picture

This may be a dumb question but since the classes are dynamic how do you add those to just stable?

lauriii’s picture

Couldn't we just move the logic from template_preprocess_views_view to stable9_preprocess_views_view?

lendude’s picture

Status: Needs review » Needs work

Yeah that should work, just add that snippet in #17 to stable9

lendude’s picture

Status: Needs work » Needs review

Did what @lauriii suggested. The other case in stable9.theme that seems to have done this didn't get test coverage as far as I can tell, so no test coverage for that for now

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Change looks good.

So if this the path forward for any other class removals?

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

This looks good but we need a change record.

Something like 'Views used to duplicate custom classes like my__class added in the views UI into an additional my--classas a backwards compatibility layer. This backwards compatibility layer has now been moved to the Stable9 theme. If you were relying on these classes, you should either update your CSS to target the correct class, or add Stable9 as a dependency of your theme'

catch’s picture

Title: Decide what to do with the BC css class from the Views UI » Move the bc layer for views UI CSS classes from views to stable9
smustgrave’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record

Created a CR from #27.

Made the recommendation to target the correct CSS classes. Do we know how long stable9 will be around? If that should be added to the CR.

quietone’s picture

I'm triaging RTBC issues. I read the IS and the comments. I didn't find any unanswered questions or other work to do. Although, the proposed resolution is a bit out of date.

Leaving at RTBC.

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

  • nod_ committed 3923a9f8 on 11.x
    Issue #2977950 by Lendude, smustgrave, lauriii: Move the bc layer for...
nod_’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3923a9f and pushed to 11.x. Thanks!

Not backporting, so that it'll only be released with D11.

Status: Fixed » Closed (fixed)

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