Hi,

I would like to add two or more classes in the wrapper class. Currenlty it seems views concatenate the arguments with dashes. "my_class1 my_class2" produces a unique class "my-class1-my-class2". Not very handy IMO. I would prefer to have "my-class1 my-class2".

J.

Comments

merlinofchaos’s picture

Status: Active » Closed (duplicate)

No need for multiple issues. I see you're already on the other issue: http://drupal.org/node/939992

dboulet’s picture

Status: Closed (duplicate) » Active

In my opinion, that other issue isn't quite the same thing. This issue is about allowing multiple classes, while the other is about errors thrown when certain characters are included in the class name.

I'll look into creating a patch for this.

Jej’s picture

Status: Needs review » Active

I thought too but drupal policemen are watching :) I don't contribute for so long in drupal, but I really feel this community is under stress!

The patch is quite easy, I just added a filter array argument in the drupal_clean_css_identifier()'s. The filter is array('_' => '-', '/' => '-', '[' => '-', ']' => ''), see in includes/common.inc (function drupal_clean_css_identifier).

I cannot give the patch, because at the end I believed it was a bad idea (nobody seems to need that...), then I managed to do a different way, and I updated views module over my modifications...

Jej

merlinofchaos’s picture

Jej: Well, patching a drupal core function is not an option for us, so your definition of 'quite easy' does not match mine. Then again, you want to refer to us as 'Drupal policemen' so I guess we're the enemy rather than people trying to help.

dboulet: Okay, yes, I agree that we shouldn't be converting spaces to dashes.

Jej’s picture

merlinofchaos:

Hi,

I don't suggest to patch the core, maybe I was not clear enough. Views uses a core function (drupal_clean_css_identifier) that allows to change the default filter. By default ' ' are translated to '-', so it avoids to use two classes. I proposed to override $filter in Views calls (without space conversion), so it accepts two classes.

function drupal_clean_css_identifier($identifier, $filter = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => ''))

It was working like this before I change my mind (read #3 above). Maybe I did'nt understand the way Views works regarding classes attribution, relations with other modules, etc. I fall in doubt and I didn't want really to enter in the debate (no time, need a working site), so I decided to erase my local changes and rely safely on the default behaviour.

Sorry to shock you with my (too quick) comment, regarding my feeling in this community. I can understand that, as you seem to be a great contributor in Drupal, what I respect. Sorry for that. On my side, I was just a bit disappointed (not the 1st time in life but...) to feel foolish with my firmly closed feature request! Tired to see or have to debate everywhere, all the time... except perhaps when it might be pleasant :)

J.

dboulet’s picture

Status: Active » Needs review
StatusFileSize
new2.79 KB

Here's what makes sense to me, please review.

merlinofchaos’s picture

Status: Active » Needs review

I'm not sure we need to explode here. I think I'd rather just go with our own replacement for drupal_clean_string_identifier -- we used to have views_css_safe(). Maybe we need to resurrect that.

Jerome F’s picture

I'm also trying to use two classes in an element class. Can't find a work around. I found this issue which matches the use case. I've noticed that the wrapper classes make use in last dev-1 of the explode and therefore I can put several classes there but no "Replacement patterns" ar available for the wrapper.

I tried the patch though which is now a bit different because of the recent modifications in views_handler_field.inc
It works for me.

Attached updated patches for theme/theme.inc and handlers/views_handler_field.inc.

I think I'll settle for a bigger css code with just one class for the moment, for my production site I have to release, instead of relying on a patch when I don't know the outcome of this issue.

dawehner’s picture

Status: Needs review » Needs work

Can you please create a single patch for this issue? This would be cool

Additional some kind of usage of drupal code style would be helpful, too. So for example use two spaces instead of a tab.

Jerome F’s picture

StatusFileSize
new2.49 KB

Here we are dereine, I just updated the patch in #6 to matc the code lines. I tested this patch, and it works, I can now add more classes to one element in a view.

dboulet’s picture

The patch will work, but merlinofchaos suggested in #7 that we not use this method. Unless he changes his mind, we need to come up with a new patch that replaces explode() and drupal_clean_string_identifier() with our own sanitizing function.

Jej’s picture

Why not just override the $filter parameter in drupal_clean_css_identifier?? (sorry to insist)

function drupal_clean_css_identifier($identifier, $filter = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => ''))

The default $filter is array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')

Should be array('_' => '-', '/' => '-', '[' => '-', ']' => '') to avoid space replacement.

Jej

dboulet’s picture

I don't think that it'll work Jej, I'm pretty sure that drupal_clean_css_identifier() filters out "invalid" characters (including spaces) after the replacements have been made.

Pisco’s picture

@dboulet

I'm pretty sure that drupal_clean_css_identifier() filters out "invalid" characters (including spaces) after the replacements have been made.

No it doesn't, and a whitespace is by no means an invalid character in that context. drupal_clean_css_identifier is overly aggressive anyway, that's why I filed bug: #1109854: Overly aggressive transliteration in drupal_clean_css_identifier removes underscores from classes.

dboulet’s picture

Status: Fixed » Needs work
$ drush php-eval 'print drupal_clean_css_identifier("one two") . "\n";'
one-two
$ drush php-eval 'print drupal_clean_css_identifier("one two", array("_" => "-", "/" => "-", "[" => "-", "]" => "")) . "\n";'
onetwo

Spaces are always stripped out.

merlinofchaos’s picture

Status: Needs work » Needs review

There's a new patch but status was never set to needs review!

merlinofchaos’s picture

Status: Needs review » Fixed

Committed and pushed #10. Thanks!

Pisco’s picture

Status: Fixed » Needs review

@dboutlet you're right, the common space character U+0020 does indeed get stripped out by drupal_clean_css_identifier, as anything below U+00A1. This shows how broken drupal_clean_css_identifier, try the same with any other space character like U+2002, EN SPACE, U+2003, EM SPACE or any other whitespace character above U+00A1:

$ drush php-eval 'print drupal_clean_css_identifier("one\xe2\x80\x82two") . "\n";'
one two
$ drush php-eval 'print drupal_clean_css_identifier("one\xe2\x80\x83two") . "\n";'
one two

Instead of using escape sequences, you can try these examples by directly typing the respective Unicode characters, it'll still work.

Pisco’s picture

Status: Needs review » Fixed

Sorry @merlinofchaos, didn't mean to change the status, you changed the status while I was still writing a reply.

merlinofchaos’s picture

I assume crosspost changed status.

Pisco’s picture

In #939992: "CSS classes must be alphanumeric or dashes only." I think underscores should be included which is targeted at 6.x-3.x, I was referred to this ticket, when I argued that underscores U+005F in CSS classes should be allowed and possible too. Now #10 solved the problem of allowing more than one CSS class but still involves drupal_clean_css_identifier, which replaces underscores by dashes. What should I do, file a new ticket for 7.x-3.x?

Pisco’s picture

Filed a new feature request with a patch based on #10: #1111258: Allow underscores in CSS classes, thanks.

drunken monkey’s picture

I think this was somehow applied wrongly. Comparing the patch in #10 and the current code in Git, somehow the explode() call is missing. This means a string is handed to array_map() and implode(), resulting in tons of error notices.

dboulet’s picture

Status: Needs review » Needs work

Yup, comparing the commit to the patch above, you see that they do not match.

dboulet’s picture

Status: Needs work » Needs review
StatusFileSize
new1.03 KB

This should fix it I think.

EDIT: I've marked #1051034: Allow field wrapper class to take multiple classes as a duplicate of this of this issue. I've included a change in this patch to modify the code committed in that issue to be more consistent with our patch here.

merlinofchaos’s picture

Status: Needs work » Fixed

Whoops. My push to fix the missing explode got missed so that was sitting in my local repo overnight. One of the loops not getting changed to array_walk I had missed, tho, so pushed those as separate commits.

Status: Fixed » Closed (fixed)

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