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
For the D7 upgrade site: Check in Admin Bar > Configuration > URL handling > URL settings Is 'Enable clean URLs' checked?
$_GET empty
May I append a question here? I seem to have a similar issue: Two Backdrop 1.30.1 portals, both running on the same server (Apache, PHP, MariaDB), both with the same enabled modules...
$_GET empty
Thank you; the answer was beneficial, except that Backdrop does not appear to have a 'Webform Rules' module. Support at:https://web.archive.org/web/20200214234910/http://justinphelan.com/post/...
How to attach a file to a Webform confirmation email
@yourkshirepudding @Enthusiast Thank you! I see - I was overthinking it. Just creating a new content type makes the most sense. I don't know why I thought the BLOG module was...
Blog module questions
This can be done with any Content type. You can set "Default URL alias pattern" for Content type of "/blog/[node:author:uid]/[node:created:raw]" (short and beautiful unique path) and...
Blog module questions