Hi there.

We have developped many modules in Drupal and everytime we need to manipulate user informations, we user our own "Views" to filter and point to edit.

Last time, we added a module_invoke_all() in the users_filter() function and added our own filters directly from the user administration and things worked right-out-of-box. So I would like to suggest to permanently add this one line in the function, here it is:

// Added in users_filter() (file user.module line #1982)
$filters = module_invoke_all('user_filters', $filters);

Thank you for everything!

Comments

emichan’s picture

Version: 6.13 » 7.x-dev

Hi,

I'd like to second this request. hook_user_filters would be very useful when adding lots of data to the user object. A hook_user_filters implementation could return an associative array of filters in the same form the user_filters function currently uses:

 function mymodule_user_filters(){
    return array(
      'filter_name' => array(
         'title' => t('title'),
         'join' => 'join clause',
         'where' => 'where clause',
         'options' => array(),
      ),
    );
}

Thanks!

sun.core’s picture

Version: 7.x-dev » 8.x-dev
rohitst’s picture

Can this be done in Drupal 6.x , i see no other way than hack the core :(

bfroehle’s picture

Title: Hooks to filter users » Add hook to filter users
Status: Active » Needs review
StatusFileSize
new5.92 KB

This would be very convenient for the cas module which could then allow to filter by users with associated cas entries in the {authmap} table.

I've submitted some 'minimally intrusive' code. Basic changes to 7.x-dev:

  1. Creation of hook_user_filters(). Return value is similar to what user_filters() current returns, with the addition of 'callback' and 'callback arguments' to set the function used to do implement the actual filtering.
  2. Rename user_filters() to user_user_filters() [so that it implements the hook]. Add 'callback' of 'user_build_filter_query'.
  3. Have user_build_filter_query() expect the $filters passed as an argument instead of in $_SESSION['user_overview_filter']).
  4. Replace every instance of $filters = user_filters() with $filters = module_invoke_all('user_filters');
  5. Document the API addition in user.api.php

Given the required change to user_build_filter_query(), it'd be hard to argue that this should go in 7.x.... but with some slight modifications, it could be implemented in a way that didn't break any of the existing functionality.

bfroehle’s picture

+++ modules/user/user.api.phpundefined
@@ -185,6 +185,40 @@ function hook_user_operations() {
+ * The module must also implement hook_user_filter_query_alter() to do implement
+ * the actual filtering.

These lines were based upon an older method which as superseded by the 'callback' approach.

Powered by Dreditor.

bfroehle’s picture

StatusFileSize
new8.08 KB

Major revisions here. I'll update the issue status when I get a chance.

Status: Needs review » Needs work

The last submitted patch, hook_user_filters-527430-6.patch, failed testing.

bfroehle’s picture

Status: Needs work » Needs review
StatusFileSize
new8.12 KB
new691 bytes

Last patch failed because I bungled up the structure of $applied_filters. This one is manually tested to work.

thedavidmeister’s picture

Status: Needs review » Needs work

Patch no longer applies.

error: patch failed: core/modules/user/user.admin.inc:33
error: core/modules/user/user.admin.inc: patch does not apply
error: patch failed: core/modules/user/user.api.php:183
error: core/modules/user/user.api.php: patch does not apply
error: patch failed: core/modules/user/user.module:3293
error: core/modules/user/user.module: patch does not apply

That said though, is this issue still relevant with Views in core now?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpi’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

We use Views nowdays..

Marked as outdated