Commit 5d7fb1dd authored by merlinofchaos's avatar merlinofchaos

#511908 by dww: Too many check plains in selects because of problems with checkboxes.

parent 962fe2ae
......@@ -47,6 +47,7 @@ Views 2.x-dev
o #561892 by dereine: Unchecking "rewrite this field" but leaving a value caused field to be rewritten anyway.
o #408894 by dereine: Views AJAX incorrectly used "access content" permission.
o #574150 by dereine: Remove user search because user.module does not store user keywords.
o #511908 by dww: Too many check plains in selects because of problems with checkboxes.
Other changes:
o Implement a post_render hook (for themes too) and cache method.
......
......@@ -173,11 +173,6 @@ class views_handler_filter_in_operator extends views_handler_filter {
}
if ($which == 'all' || $which == 'value') {
if ($this->value_form_type == 'checkboxes') {
foreach ($options as $key => $option) {
$options[$key] = check_plain($option);
}
}
$form['value'] = array(
'#type' => $this->value_form_type,
'#title' => $this->value_title,
......@@ -191,18 +186,27 @@ class views_handler_filter_in_operator extends views_handler_filter {
$form_state['input'][$identifier] = $default_value;
}
$process = array();
if ($this->value_form_type == 'checkboxes') {
// If this form element will use checkboxes in the UI, we need to
// check_plain() all the options ourselves since FAPI is inconsistent
// about this. However, instead of directly doing that to the #options
// right now, we define a #process callback since we might change our
// mind later and convert this into a 'select' form element, which
// would lead to double-escaping the options.
$process[] = 'views_process_check_options';
}
if ($which == 'all') {
$process = array();
if (empty($form_state['exposed']) && ($this->value_form_type == 'checkboxes' || $this->value_form_type == 'radios')) {
$process[] = "expand_$this->value_form_type";
$form['value']['#prefix'] = '<div id="edit-options-value-wrapper">';
$form['value']['#suffix'] = '</div>';
}
$process[] = 'views_process_dependency';
$form['value'] += array(
'#process' => $process,
'#dependency' => array($source => $this->operator_values(1)),
);
$form['value']['#dependency'] = array($source => $this->operator_values(1));
}
if (!empty($process)) {
$form['value']['#process'] = $process;
}
}
}
......
......@@ -280,3 +280,20 @@ function views_process_dependency($element, $edit, &$form_state, &$form) {
return $element;
}
/**
* #process callback to see if we need to check_plain() the options.
*
* Since FAPI is inconsistent, the #options are sanitized for you in all cases
* _except_ checkboxes. We have form elements that are sometimes 'select' and
* sometimes 'checkboxes', so we need decide late in the form rendering cycle
* if the options need to be sanitized before they're rendered. This callback
* inspects the type, and if it's still 'checkboxes', does the sanitation.
*/
function views_process_check_options($element, $edit, &$form_state, &$form) {
if ($element['#type'] == 'checkboxes' || $element['#type'] == 'checkbox') {
$element['#options'] = array_map('check_plain', $element['#options']);
}
return $element;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment