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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

knalstaaf’s picture

Maybe 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.

hein.corbet’s picture

I 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.

knalstaaf’s picture

Title: Update to 7.x-1.14 breaks displays using CCS classes with spaces » Update to 7.x-3.14 breaks displays using CCS classes with spaces
Issue summary: View changes
FileSize
893 bytes

Works brilliantly, thanks! Added it as a patch (generated with PHPstorm, so bear with me).

Paul Lomax’s picture

Patch works for me, cheers

szt’s picture

Status: Active » Reviewed & tested by the community
knalstaaf’s picture

jeni_dc’s picture

The 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.

jeni_dc’s picture

Status: Reviewed & tested by the community » Needs review
ac’s picture

Category: Support request » Bug report
Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Patch works - this is a major issue and has caused big issues on many of our sites.

tawiiams’s picture

The 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.

Mirakolous’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.01 KB

Patch 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.

Status: Needs review » Needs work

The last submitted patch, 11: views-classes_with_spaces-2752617-11.patch, failed testing.

The last submitted patch, 11: views-classes_with_spaces-2752617-11.patch, failed testing.

DamienMcKenna’s picture

Version: 7.x-3.14 » 7.x-3.x-dev
Status: Needs work » Needs review
Parent issue: » #2855120: Plan for Views 7.x-3.16 release

Yeah, we should try to get this into 3.16.

Status: Needs review » Needs work

The last submitted patch, 11: views-classes_with_spaces-2752617-11.patch, failed testing.

Mirakolous’s picture

It 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.

Mirakolous’s picture

Status: Needs work » Needs review

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. 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

Status: Fixed » Closed (fixed)

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

drewble’s picture

The 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.

drewble’s picture

UPDATE: Discovered an error in my previous patch. Added a condition to make sure that field_tags exists as an element in the row.

DamienMcKenna’s picture

@drewble: Could you please create a new issue for this? Thanks.