Provide views definitions for file_managed uid
Currently, when you create a View of files, you can't include the uid of the author as a field, nor can you use uid as a filter. Having uid available as field, filter and relationship would be very helpful. For example, it would allow you to create views where you can have a contextual filter that defaults to the currently logged in user, thus limiting the view of files to only the person who's logged in. Of course, there are other helpful use cases.
The snapshots below just show that a filter by uid is not currently available.
I'd like to clarify a bit, to prevent misunderstandings: the relationship is available, so under section "Relationship" (right side of the views UI) one can add the File: User who uploaded relationship. Then the whole user object is available for fields, filters...
What seems to be missing is the simple uid as regular field (filter, sort) value without this additional relationship.
"uid" is a column in db table file_managed, so there's no obvious reason, why field/filter/sort/argument shouldn't provide the simple (numeric uid) value. Very likely this is an oversight.
"uid" doesn't provide much on its own, for most real-world uses, the relationship (LEFT JOIN {users}) still needs to get set. But that's no explanation, why no handler's set at all for plain uid.
A PR is available for testing and review. I didn't add the "sort" handler, as the node views data definition also doesn't seem to have it. But filter, argument and field are available now. Search for the "File: User who uploaded" item (without any additional relationship set).
I'd like to clarify a bit, to prevent misunderstandings: the relationship is available, so under section "Relationship" (right side of the views UI) one can add the File: User who uploaded relationship. Then the whole user object is available for fields, filters..
Thanks for the clarification. I totally missed the user relationship - I was looking for the field using the Views UI javascript filter with the keyword "Author" (which is what the uid relationship is called for Content), but for files this relationship is called "User" instead of "Author".
You are right - having that is enough to allow someone to filter by uid (after creating the relationship and using that as a bridge to the uid of the user entity).
Thanks for providing the PR anyways! I'll test.
PR LGTM and RTBC.
I was looking for the field using the Views UI javascript filter with the keyword "Author"...
Yeah, a follow-up re wording / naming might make sense. Follow-up, because naming issues usually need a little more discussion. ("Author who uploaded" wouldn't make sense... :wink:)
Thanks @argiepiano and @indigoxela! I merged https://github.com/backdrop/backdrop/pull/4686 into 1.x and 1.27.x.
I did slightly reword the the description on the field from
If you need more fields than the uid add the File: User who uploaded relationship
to:
If more fields than UID are needed, add the "File: User who uploaded" relationship.
I'm not sure if it's an official code style thing, but I don't like talking "directly to the user" using "you" or "your" unless talking about their user account. i.e. I would avoid "You have saved your view." but "You can update your password." is fine.
... but for files this relationship is called "User" instead of "Author".
Yeah, a follow-up re wording / naming might make sense. ...
Yes, follow-up PR/issue 👍🏼 ...however, do note that when changing strings that use the word user on its own, we usually try to change that to either user account or person, whichever makes more sense and is appropriate.