Drupal Views exposed filter of Author name as a drop down -
this follow question drupal views exposed filter of author name. following question answered , works. can filter view user name. user name entered entered typing in box , box auto completes. rather doing list of users drop down. need 1 user selected. know if possible?
you'll need custom module that.
i've done drupal 7 way: create module, say, views_more_filters
, have views_more_filters.info
file this:
name = views more filters description = additional filters views. core = 7.x files[] = views_more_filters_handler_filter_author_select.inc files[] = views_more_filters.views.inc
(file views_more_filters_handler_filter_author_select.inc
contain our filter handler).
a basic views_more_filters.module
file:
<?php /** * implements of hook_views_api(). */ function views_more_filters_views_api() { return array('api' => 3); }
then define filter in views_more_filters.views.inc
:
<?php /** * implements of hook_views_data(). */ function views_more_filters_views_data() { return array( 'node' => array( 'author_select' => array( 'group' => t('content'), 'title' => t('author uid (select list)'), 'help' => t('filter author, choosing dropdown list.'), 'filter' => array('handler' => 'views_more_filters_handler_filter_author_select'), 'real field' => 'uid', ) ) ); }
note set author_select
machine name of filter, defined filter handler ('handler' => 'views_more_filters_handler_filter_author_select'
) , field filter ('real field' => 'uid'
).
now need implement our filter handler. our filter functions default views_handler_filter_in_operator
, extend class in views_more_filters_handler_filter_author_select.inc
file:
<?php /** * custom filter handler */ class views_more_filters_handler_filter_author_select extends views_handler_filter_in_operator { /** * override parent get_value_options() function. * * @return * return stored values in $this->value_options if expects it. */ function get_value_options() { $users_list = entity_load('user'); foreach ($users_list $user) { $users[$user->uid] = $user->name; } // don't need guest user here, remove it. unset($users[0]); // sort username. natsort($users); $this->value_options = $users; return $users; } }
we haven't had here: populate options array list of our users, rest handled parent class.
for further info see:
Comments
Post a Comment