I thought I'd post this here in case it may help someone else. It took a while to figure out.
Backdrop's Form API provides the element managed_file, which allows you to add a widget to your forms to upload new managed files. The documentation for this element is good, except that it doesn't contain much about the property #browser_view, other than saying that it allows developers to indicate a View to use in the file browser dialog.
So, my use case was: I needed to provide a file browser that allowed the user to pick PDF documents from the managed files (not images). These are the steps:
1. Create your form and include the managed_file element. For example:
$form['certificate_template_file'] = array( '#type' => 'managed_file', '#title' => t('Template PDF file'), '#description' => t('The template PDF file to be used for this certificate.'), '#default_value' => $certificate_template->certificate_template_file, '#upload_location' => 'public://certificate_templates', '#upload_validators' => array( 'file_validate_extensions' => array('pdf'), 'file_validate_size' => array(5 * 1024 * 1024), ), '#browser_view' => 'pdf_doc_library', );
The above indicates that the View "pdf_doc_library" will be used for the file browser.
2. Create your View. Show: Files. I used a Grid display.
3. This is important: in the Grid settings, add the Row class "file-browser-file". Backdrop's file browser will look for that class to select the file ID when clicked.
4. Notice the hidden fields Path and Name (image above). The Path field MUST have the option "Use full URL instead of file storage URI" clicked.
The other important part: rewrite the File ID fields as follows:
The important part here is to provide a data-file-url, AND a data-fid with the data from the hidden fields. The rest you can customize as you wish.
5. Then a bit of styling added to a CSS file that gets loaded with the form, such as:
.file-browser-file:hover { background-color: #e5f3ff; } .file-browser-selected { background-color: #cce8ff; }
That's it. Then, in the form, when clicking "Select existing files" you'll get:
A minor annoyance: the dialog has the title "Select from Image Library". That title is, unfortunately, hard-coded in file_managed_file_browser_open(). Perhaps I'll create an issue for this. It'd be easy to pass the title within $form_state.
Recent comments
Thanks! The site was on PHP 7.0. With assistance from my hosting provider, I updated to PHP 7.4 and now I have access to the site again. No database re-import required.
Locked out of site after updating modules
Thank you very much. I will follow your advice.
Locked out of site after updating modules
The best you can do is test and report. If you find a contrib that doesn't work in php 8.3, create an issue in its queue so it gets fixed. In my experience, I've found that 7.4 is safest...
Locked out of site after updating modules
Hi argiepiano, Some contrib will not work in php 7.2 or lower, and some will not on PHP 8.1 or higher. Is there a way to find out which is the optimal PHP version for a...
Locked out of site after updating modules
This sounds like a combination of a buggy module and the "wrong" version of PHP. The fact that you are being redirected to the maintenance page may be an indication that your site was put on...
Locked out of site after updating modules