public function views_handler_filter_in_operator::validate in Views (for Drupal 7) 7.3
Same name and namespace in other branches
- 6.3 handlers/views_handler_filter_in_operator.inc \views_handler_filter_in_operator::validate()
Validates the handler against the complete View.
This is called when the complete View is being validated. For validating the handler options form use options_validate().
Return value
array Empty array if the handler is valid; an array of error strings if it is not.
Overrides views_handler::validate
See also
views_handler::options_validate()
File
- handlers/
views_handler_filter_in_operator.inc, line 429 - Definition of views_handler_filter_in_operator.
Class
- views_handler_filter_in_operator
- Simple filter to handle matching of multiple options using checkboxes.
Code
public function validate() {
$this
->get_value_options();
$errors = array();
// If the operator is an operator which doesn't require a value, there is
// no need for additional validation.
if (in_array($this->operator, $this
->operator_values(0))) {
return array();
}
if (!in_array($this->operator, $this
->operator_values(1))) {
$errors[] = t('The operator is invalid on filter: @filter.', array(
'@filter' => $this
->ui_name(TRUE),
));
}
if (is_array($this->value)) {
if (!isset($this->value_options)) {
// Don't validate if there are none value options provided, for example
// for special handlers.
return $errors;
}
if ($this->options['exposed'] && !$this->options['expose']['required'] && empty($this->value)) {
// Don't validate if the field is exposed and no default value is
// provided.
return $errors;
}
// Some filter_in_operator usage uses optgroups forms, so flatten it.
$flat_options = form_options_flatten($this->value_options, TRUE);
// Remove every element which is not known.
foreach ($this->value as $value) {
if (!isset($flat_options[$value])) {
unset($this->value[$value]);
}
}
// Choose different kind of ouput for 0, a single and multiple values.
if (count($this->value) == 0) {
$errors[] = t('No valid values found on filter: @filter.', array(
'@filter' => $this
->ui_name(TRUE),
));
}
}
elseif (!empty($this->value) && ($this->operator == 'in' || $this->operator == 'not in')) {
$errors[] = t('The value @value is not an array for @operator on filter: @filter', array(
'@value' => views_var_export($this->value),
'@operator' => $this->operator,
'@filter' => $this
->ui_name(TRUE),
));
}
return $errors;
}