Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By peterk900 on
I am trying to write code to create a custom filter replacing views_handler_filter_string in the code snippet below. This code would replace the text box that the default filter provides with a select box filled with values from a database table.
// The Name field
$data['exposed']['name'] = array(
'title' => t('Name'),
'help' => t('The record name.'),
'field' => array(
'handler' => 'views_handler_field',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
Please can someone point me at code that illustrates how to do this - including finding the classes that the standard filter uses. Thanks.
Comments
Use Views AutoComplete Filter
Perhaps a lazy way out but I can manage to achieve almost what I want out of the box with the module Views Autocomplete Filter. Not a drop down but acceptable, and preferable if the number of selectable items is large. Here is a good video on this module.
I mean to return to this issue of creating custom filters via code and I found this post which appears to have solved the problem. However I am puzzled by the presence of the $string parameter in the callback as it does not seem to be defined elsewhere in the code (see below) and there are only two arguments in the hook_menu item. If anyone has any comments on this then please post. Thanks.