How can I make a custom views filter handler to filter a list of users which the current user created?

For example: The user adds members to the site a view will show only the members that the user added.

In views, there is a relationship for sorting content based on the current user "Content authored" which is similar.

enter image description here

  • 1
    You can't because there is no such field in the user table. So first you need to create this field and fill it with data.
    – 4uk4
    Jul 18, 2018 at 12:35

1 Answer 1


As pointed out by 4k4 there is no user authored data in the tables, so I thought I would add what I did to output a view of users the author created.

For me, I needed to do some of this in my custom module you might be able to do this in the configuration if your use case is easier.

 1. Create user reference field in /admin/config/people/accounts/fields
 2. Install https://www.drupal.org/project/cer/
 3. Add a corresponding reference in /admin/config/content/cer for your field and the user entity.
 4. Create a relationship for your view from the user field.
 5. Output your view as a block list on your user account page.

Now when a user creates a reference the view will shorten to a list of your users.

I took this a step further and created a custom form module to register a user and in code populate the user entity reference field with a form submit for the current user's id. This bit took me a while to work out so hope this helps someone else. :)

$userCurrent = \Drupal::currentUser();
$uid = $userCurrent->id();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.