The last update of my Views from 7.x-3.13 to 7.x-3.14 broke my masonry grid view based on Bootstrap 3. My tokens use spaces in their output, like col-xs-12 col-sm-6 col-md-3 col-lg-3
, but now they're all being glued together: col-xs-12-col-sm-6-col-md-3-col-lg-3
. The spaces are all being replaced with dashes / hyphens. Currently there's no alternative left to achieve this with Views (providing a user friendly method the site manager to assign widths and heights) that I know of immediately.
It is related to this thread: #1262630: Raw value tokens not replaced if used in css class
That thread is still set as "needs review" on the day of this writing, has Drupal 8 mentionned on it, but is committed to Views 7.x-3.14? I figure there must be a good reason for this, but which one would that be if I may ask kindly?
Comment | File | Size | Author |
---|---|---|---|
#22 | views-classes_with_spaces-2752617-22.patch | 1.43 KB | drewble |
#21 | views-classes_with_spaces-2752617-21.patch | 1.33 KB | drewble |
#16 | views-classes_with_spaces-2752617-16.patch | 707 bytes | Mirakolous |
| |||
#11 | views-classes_with_spaces-2752617-11.patch | 1.01 KB | Mirakolous |
#7 | views-classes_with_spaces-2752617-7.patch | 707 bytes | jeni_dc |
|
Comments
Comment #1
knalstaaf CreditAttribution: knalstaaf commentedMaybe the best solution would be to let the developer decide whether spaces should be preserved or not in the output of tokens in row classes, by means of a checkbox in the settings of the field where they come from, since this behaviour also affects the no results behaviour.
If you'd consider that as a valid idea, feel free to change this thread to a feature request.
Comment #2
hein.corbet CreditAttribution: hein.corbet commentedI faced the same problem. When using a node field with multiple classes (space separated). Found a solution in changing the file views_plugin_style.inc change the function get_row_class($row_index).
remove: $classes[] = strip_tags($this->tokenize_value($token_class, $row_index));
add: $classes = array_merge($classes, explode(' ', strip_tags($this->tokenize_value($token_class, $row_index))));
this will explode the space separated classes into array elements.
Comment #3
knalstaaf CreditAttribution: knalstaaf commentedWorks brilliantly, thanks! Added it as a patch (generated with PHPstorm, so bear with me).
Comment #4
Paul Lomax CreditAttribution: Paul Lomax commentedPatch works for me, cheers
Comment #5
szt CreditAttribution: szt commentedComment #6
knalstaaf CreditAttribution: knalstaaf commentedComment #7
jeni_dc CreditAttribution: jeni_dc commentedThe patch in #3 didn't apply for me since the path to the file being patched is incorrect, it contains directories outside of views. Here's a new patch that fixes the file path created with git.
Comment #8
jeni_dc CreditAttribution: jeni_dc commentedComment #9
acPatch works - this is a major issue and has caused big issues on many of our sites.
Comment #10
tawiiams CreditAttribution: tawiiams as a volunteer commentedThe patch didn't fix my view. It looks to be the same issue. My view is set up with an HTML list with a list class of '.cols3 .Main-listings-list--item'. For now I've just rolled back to 7.x-3.13 as the security risk doesn't affect me.
Comment #11
Mirakolous CreditAttribution: Mirakolous commentedPatch did not fix my problem. My issue (and probably tawiiams) was that drupal_html_class() converts the classes to lowercase. Using capital letters in classes is technically valid, so in my opinion, the function should remain drupal_clean_css_identifier() which is basically drupal_html_class() without the strtolower(). I rerolled jeni_dc's patch to also fix this.
Comment #14
DamienMcKennaYeah, we should try to get this into 3.16.
Comment #16
Mirakolous CreditAttribution: Mirakolous commentedIt looks like the additional part I added got committed to dev elsewhere thus causing the patch to fail. I am attaching another patch without it so that this issue can stay in Needs review status. I am adding author jeni_dc from #7 since it should be identical.
Comment #17
Mirakolous CreditAttribution: Mirakolous commentedComment #19
DamienMcKennaCommitted. Thanks everyone, and I'm sorry it took so long for this regression to be fixed.
BTW I've created a changenotice for this: https://www.drupal.org/node/2866151
Comment #21
drewble CreditAttribution: drewble as a volunteer commentedThe current 7.x-3.16 branch was not working the way I expected. For readability, my field_tags are written with spaces, so when they are output as classes the whitespace needs to be replaced with a non-whitespace character such as a hyphen. I understand the issue at the top of this thread where multi-value fields are output as a single hyphenated class and I have taken steps in my patch to handle both cases.
If a single tag is made up of more than one word, separated by whitespace this patch will replace the whitespace with hyphens. If the tag is already hyphenated, it is left alone. If field_tags has multiple values, the get_row_class function pulls the value of the multi_type separator and inserts it into a preg_replace pattern. Multiple tags are preserved as multiple classes.
Comment #22
drewble CreditAttribution: drewble as a volunteer commentedUPDATE: Discovered an error in my previous patch. Added a condition to make sure that field_tags exists as an element in the row.
Comment #23
DamienMcKenna@drewble: Could you please create a new issue for this? Thanks.