function mvf_handler_filter_mvf::build_group_validate in Measured Value Field 7
Validate the build group options form.
Overrides views_handler_filter::build_group_validate
File
- views/
mvf_handler_filter_mvf.inc, line 177
Class
- mvf_handler_filter_mvf
- Base Views Filter Handler for field types defined in MVF module.
Code
function build_group_validate($form, &$form_state) {
// Out of the box our filter does not pass validation because our
// value is an array of arrays, however, here is expected at most array of
// strings/floats, or just a scalar value. So we need to substitute
// our values with some dummy values that will pass validation and handle
// input validation itself here in our method.
$group_items = $form_state['values']['options']['group_info']['group_items'];
// Our value will be substituted for parent's method call with this value
// once we have validated it ourselves. This way we make sure no groundless
// validation errors occur.
$passable_value = 'pass me';
foreach ($group_items as $id => $group) {
// We keep only those sub arrays of 'value' that make sense for the
// selected operator.
$operator = $this
->operators();
$required_subvalues = drupal_map_assoc($operator[$group['operator']]['required subvalues']);
$group['value'] = array_intersect_key($group['value'], $required_subvalues);
$is_valid = TRUE;
foreach ($group['value'] as $subvalue) {
// For validation we use hook_field_is_empty().
if (module_invoke('mvf', 'field_is_empty', $subvalue, $this->options['field_definition'])) {
$is_valid = FALSE;
break;
}
}
if ($is_valid) {
// If this group is valid, we substitute its value with something
// that will pass validation in parent's method.
$form_state['values']['options']['group_info']['group_items'][$id]['value'] = $passable_value;
}
}
parent::build_group_validate($form, $form_state);
// Restoring real values once we are done with calling parent's method.
$form_state['values']['options']['group_info']['group_items'] = $group_items;
}