Closed (fixed)
Project:
Field Formatter Class
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
16 May 2020 at 15:09 UTC
Updated:
2 Jul 2020 at 18:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
avpadernoComment #3
pradeepjha commentedComment #4
pradeepjha commentedWith the help of this patch, it won't replace `_` with `-`. But in this patch, I'm passing some hardcoded strings filters ( ref: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Util... ) excluding `_` to cleanCssIdentifier static method.
Comment #5
tusch001 commentedThanks for the patch and for the fast response. The patch works great (and saved me a lot of time :-)
I don't know if you update the next version, please keep in mind that also in the id underscores are valid for the name. I didn't have to replace anything there and I don't know if it is relevant at all.
I hope the cleaning of class names from underscores is not a general drupal requirement.
Enjoy the rest of Sunday!
Comment #6
mahtabalamInstead of passing hardcoded strings filters , it would be better to give a checkbox option in the display setting where classes are being added to include '_' or not.
Because passing of static filters does't look good by using core APIs.Drupal generally uses "_" for machine name that's why it were removed..
can we have any other alternative to make it as per Drupal standard?
Comment #7
pradeepjha commentedHi @MahtabAlam There are fixed number of string filters ( check here https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Util...) i.e.
That's why for now, I've passed all filters except `_` as a 2nd argument to the function.
Yes but other option can be creating a textfield, where we can give comma separated filters values. Then in code base side we can converts those values into array. And then pass it as 2nd arguments. But this need feature work and have to write test cases.
Comment #8
ramya balasubramanian commentedThanks, @pradeepjha. This looks good to me
Comment #9
avpadernoThe call to
Html::cleanCssIdentifier()has been introduced in commit 9080241b6aa20de49bd3027627f8d67579343dd0.Before that commit, the underscores weren't replaced by hyphens.
IMO, the correct plan is:
Comment #10
andrewmacpherson commentedThanks for working on this everybody. This is a very unfortunate, but very interesting bug.
Indeed. That method is the cause of underscores being replaced with hyphens. However the bug didn't actually happen until the next commit. Going by git bisect, the bug was introduced by
7d58d19. That seemed odd to me, so I looked at both issues.Then I realized something strange. If using
9080241, the class is output twice! One preserves the underscore, and the other changes it to a hyphen. So if you put "custom_class" in the formatter settings, the output iscustom_class custom-class. It turns out the commit for issue #2990781 wasn't the same as the patch submitted for the issue. So it needed another commit in a follow-up issue. Phew, that mystery is solved.Recap. What has changed:
However #2990781: Token Support was about adding token support only. The change to
Html::cleanCssIdentifier()wasn't necessary for that, and was clearly out of scope for the issue.Interestingly,
HTML::cleanCssIdentifier()leaves a double-underscore intact. That's common in BEM-style classes. Sites using this module to inject a double-underscore class will not have been affected by this issue.Agreed. To my mind that means restoring the use of
HTML::escape(), not tweakingHTML::cleanCssIdentifier()arguments.The module usage statistics were useful. Luckily, they were still available all the way back to the day before the 8.x-1.2 release.
No, I don't want to support that. This module only aims to provide simple formatter settings. The idea of an additional formatter setting, which controls what you're allowed to write in the nearby class text box doesn't make sense to me. If you don't need an underscore, just don't type it. I don't want to add a separate settings page either, for super-administrators to limit what lesser administrators can do. This module has been in use for a decade now, and that feature has never been asked for.
Comment #12
andrewmacpherson commentedI've changed it back to using
Html::escape()instead ofHtml::cleanCssIdentifier().@pradeepjha I didn't use your patch, but you'll still get an issue credit.
There will be an 8.x-1.4 release very shortly.
Comment #13
pifagorGood catch
Comment #14
pifagorAdd issue credit for:
Tusch001, kiamlaluno, andrewmacpherson