Skip to content

9.5. Filtering users by role

jeff-h edited this page Oct 17, 2016 · 2 revisions
  1. Subclass DataProviderEntity
  2. Implement dataProviderClassName() in your resource entity class and point it to the class from step 1 as per Assigning a different data provider
  3. Override method queryForListFilter()
  4. In queryforListFilter() add a special query tag and add the requested roles to the query metadata
  5. In your custom.module implement hook_query_alter()
  6. In hook_query_alter(), retrieve the roles from the query metadata, and use them in a join with the USERS_ROLES table like this:
      $query->leftJoin('users_roles', 'ur', 'users.uid = ur.uid');
      $query->condition('ur.rid', $rids, 'IN');

Example URL

In this example URL, the custom resource endpoint is myusers.

http://example.com/api/v1.0/myusers?filter[roles]=1

See also:

https://github.com/RESTful-Drupal/restful/issues/811#issuecomment-214528417

Clone this wiki locally