Following the issue #511908: Values from "in_operator" exposed filters are double-escaped (SA-CONTRIB-2009-037 regression), views_handler_filter::exposed_translate does the magic of converting html checkbox input element display values into html select input element display values.
The problem is that html construct is allowed in checkbox display values (labels?), and references|contrib tried to utilized that to link user's name to its user page.
But in exposed filter selectbox it is shown as:
- Any -
<span class="views-field views-field-name"> <span class="field-content"><a href="/users/achry-febrianto" title="View user profile." class="username">Achry Febrianto</a></span> </span>
<span class="views-field views-field-name"> <span class="field-content"><a href="/users/ario-rahardjo" title="View user profile." class="username">Ario Rahardjo</a></span> </span>Desired result I think is this:
- Any -
Achry Febrianto
Ario RahardjoSo, maybe we should add strip_tags in there.
Following is the patch.
Notes: I also apply the strip_tags() to the radio thingy, assuming html is also allowed in its display value.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 1413750.patch | 1.55 KB | dawehner |
| #7 | views-checkboxes_to_select-1413750-7.patch | 1.35 KB | dozymoe |
| #3 | views-checkboxes_to_select-1413750-3.patch | 931 bytes | dozymoe |
| views_convert-checkbox-display-value-to-select.patch | 1.04 KB | dozymoe |
Comments
Comment #1
dawehnerUpdate status
Comment #2
dawehnerIn this part the form element doesn't have to be select, maybe you should better check for select. It is possible that you still have checkboxes. Sorry
Comment #3
dozymoe commentedO M G... I did not see the exception (#no_convert) thrown in there.
Patch summary: the code strips html structure, if #type is "select", which later goes to check_plain() in form_select_options().
Might as well add decode_entities() in to the mix. :3
I'm worried about the last comment in stackoverflow though, that strip_tags() would nuke
<b I forgot to close the tag.:SComment #4
dawehnerDon't you actually want to have
strip_tags(html_entity_decode($text, ENT_QUOTES)) ?
By the way the new patch looks much cleaner now!
Comment #5
dozymoe commentedI was grepping strip_tags from Drupal core, there's not many of them, I found:
and bunch of others, and took the generalization from there.
Comment #6
dawehnerCore seems to also just do a strip_tags _options_prepare_options i guess that's what we should do as well.
Comment #7
dozymoe commentedI think I overlook something else, both _options_prepare_options() and form_select_options() takes into account that the display value could be an array.
In that case the clean up logic should be in its own function, and do a recursive if the display value is an array, like they did with _options_prepare_options() and form_select_options().
On second thought, _options_prepare_options() looks very similar to form_select_options(), what's new is the strip_tags() and filter_xss() call, a clean up logic that should have been done in form_select_options() instead?
My next logical step is to copy _options_prepare_options(), except the filter_xss() part--I think that was meant for radios and checkboxes--in views; or let views depend of field|module for sake of lazyness. :p
Maybe core form.inc omitted strip_tags() on purpose to gain speed?
Hmm, this issue is now outside my comfort zone, should the clean up logic:
Comment #8
dawehnerChanged the code a bit and committed it to 7.x-3.x
Thanks for your patch!
This would be probably helpful for a backport
Comment #9
adelka commentedHi,
I have images as a label for checkboxes (configured in cck field as for example Sodexho|
).
When I use this field in exposed views, I cant see images but only html tags.
I tried first one solution and it worked only for radius, not checkboxes.
this one:
if ($form['#type'] == 'radios') {
$form['#type'] = 'select';
// Clean $form['#options'] from html tags.
foreach ($form['#options'] as &$option) {
$option = strip_tags($option);
}
}
When I tried the same for checkboxes (or whole patches) images are not visible (label is not generated, in html code is empty).
I also tried patches but didnt help.
Any clue what can be problem?
Comment #10
dozymoe commentedThe patch was made with the assumption that only plain text is going to be the label on the options in select. We didn't expect an image as its label. Since we started with that assumption what the patch does is if you have this label before:
After it goes through the patched codes would turned in to (with html elements nuked out of existence):
Also, as you can see in this dabblet mockup, even if you forced it, the browser isn't going to render the image element, natively.
What you want though is the #no_convert option, that I ran into at #3.
The #no_convert option, forced Views to display the checkbox element as is, in that Views does not convert (er, translate?) it to select element.
The comment on that code about GET conversions is weird though, dunno what it meant.
Comment #11
adelka commentedunfortunately, none of the proposed solutions work :(
I tried last patch (1413750.patch) but I get an error:
Warning: html_entity_decode() expects parameter 1 to be string, object given v decode_entities() (riadok 429 z /data/e/-/e-donaska.sk/web/includes/unicode.inc).
If its not possible to show images, then abstracted text is also great alternative.
Comment #12
dozymoe commented@adelka doesn't look like strip_tags() made an effort to extract alt, or title attribute out of an img element. :(
Also I think you are using core's Field module, as in you are making a Field with the type List (text) and the widget is Check boxes/radio buttons. So I'm quite sure that talking about writing php codes would complicate things.
Is it possible to do this instead:
Also for accessibility sake, if you have an image, make sure you have a textual representation of that image, usually in the form of alt attribute, except in this case strip_tags() would nuked it, not good. Naughty strip_tags(). That special visually hidden span element there served the same purpose I think. The title adds context in case someone is not clear of the icon's meaning. Err, but screen reader would read both the image title and the span next to it. Dunno.
Tagging with needs accessibility review (I wonder if that's a bit much :3).
Googling sodexho I found this. :o
Edit: err, the css rules for element-invisible wasn't available in Drupal 6. If you're using one you might need this in your theme css file.
Or this one from html5 boilerplate (replace visuallyhidden with element-invisible):
Comment #13
adelka commentedWorks amazing! THANK YOU DOZYMOE! :)
Comment #14
dozymoe commentedLAAAAATEEE REPLYYYYYYY -.-
Comment #15
skwashd commentedThe patch from #7 needs a review. Updating the status so it shows up on someone's radar.
Once this lands on 7.x, the patch can be backported to 6.x.
Comment #17
skwashd commentedI have tested this with 7.x-3.7 and it works without this patch. Closing.
Comment #18.0
(not verified) commentedAdd - Any - to make it clear that the html code element is about select options.