willowf's picture

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:

  1. In the user profile form, users should only be able to select images from public://avatars/.
  2. 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):

  1. See if you can somehow adopt File Library (which allows people to choose a different View for picking files in file fields)
  2. OR, see if you can play around with 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 method views::add_item() to manually add a filter in specific situations. 

 

willowf's picture

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