function views_autocomplete_filters_filter_hander_validate in Views Autocomplete Filters 7
Helper function for validate method for autocomplete filter handlers. Needed to avoid code duplicates.
See also
views_autocomplete_filters_handler_filter_string()
views_autocomplete_filters_handler_filter_combine()
4 calls to views_autocomplete_filters_filter_hander_validate()
- views_autocomplete_filters_handler_filter_combine::validate in views/
handlers/ views_autocomplete_filters_handler_filter_combine.inc - Validate that this filter instance has a corresponding autocomplete results field.
- views_autocomplete_filters_handler_filter_search_api_fulltext::validate in views/
handlers/ views_autocomplete_filters_handler_filter_search_api_fulltext.inc - Validate that this filter instance has a corresponding autocomplete results field.
- views_autocomplete_filters_handler_filter_search_api_text::validate in views/
handlers/ views_autocomplete_filters_handler_filter_search_api_text.inc - Validate that this filter instance has a corresponding autocomplete results field.
- views_autocomplete_filters_handler_filter_string::validate in views/
handlers/ views_autocomplete_filters_handler_filter_string.inc - Validate that this filter instance has a corresponding autocomplete results field.
File
- ./
views_autocomplete_filters.module, line 188
Code
function views_autocomplete_filters_filter_hander_validate(&$errors, $filter_handler) {
// Only check if this filter instance is exposed and has the autocomplete box
// checked.
if (!empty($filter_handler->options['exposed']) && !empty($filter_handler->options['expose']['autocomplete_filter'])) {
// Look through the view and find the display that this filter instance is
// part of.
foreach ($filter_handler->view->display as $display_id => $display) {
$display_filters = $display->handler
->get_handlers('filter');
foreach ($display_filters as $filter_id => $filter) {
if ($filter === $filter_handler) {
// At this point we know we are looking at the correct display,
// and we can check the fields.
// Get the fields from the correct display.
$display_fields = $display->handler
->get_handlers('field');
$missing_autocomplete_fields = FALSE;
// Distinct validation per handler type.
switch ($filter_handler->definition['handler']) {
case 'views_autocomplete_filters_handler_filter_combine':
case 'views_autocomplete_filters_handler_filter_search_api_fulltext':
$field_name = $filter_handler->options['fields'];
if (empty($field_name)) {
$missing_autocomplete_fields = TRUE;
}
break;
default:
$field_name = !empty($filter_handler->options['expose']['autocomplete_field']) ? $filter_handler->options['expose']['autocomplete_field'] : $filter_handler->options['id'];
if (empty($field_name) || empty($display_fields[$field_name])) {
$missing_autocomplete_fields = TRUE;
}
break;
}
if ($missing_autocomplete_fields) {
$errors[] = t('Field with autocomplete results is not selected for %label filter in %display display.', array(
'%label' => $filter_handler
->ui_name(TRUE),
'%display' => $display->display_title . ' (' . $display->id . ')',
));
}
}
}
}
}
}