Hi everyone,
I’m trying to restrict the image library in BackdropCMS so that when a user selects a profile picture, they can only choose images from public://avatars/
.
I managed to achieve this by adding a filter in the perfil_image_library view, but this change affects other content types that also use the image browser.
What I need is:
-
In the user profile form, users should only be able to select images from
public://avatars/
. - In other forms, the image library should work without restrictions.
I’ve tried modifying the user_picture_field
module using hook_views_query_alter()
, but it hasn’t worked as expected. I also attempted using hook_form_alter()
, but it still affects other parts of the site.
What would be the best way to restrict the image library only when selecting a user profile picture, without impacting other forms?
Thanks in advance for any suggestions!

Comments
The ideal way to do this would be create a new File type to store avatars, and to be able to specify a new View to be used as the file browser for fields that reference that new avatar File type.
But unfortunately this is not possible with the UI currently (it wouldn't be too difficult to do with a custom module, though).
Two hints that may work with some work (you'll need to do some coding for the second one):
hook_views_query_alter()
to alter the query of the Image file picker View to add the path filter only for certain fields (I haven't looked to see if this is possible)A third possibility would be to implement
hook_views_pre_view()
and use the poorly documented methodviews::add_item()
to manually add a filter in specific situations.Hi, I have not managed to solve it, I have tried another module but it works badly, so for the moment I will leave it as it is. I will continue later. Thanks for your help