Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The file scheme selection form (public, private, etc) that is present when the system has more than 1 scheme available does not respect the field's settings. My file field only allows private files, yet the form allows users to select public.
Here's a form alter I've been using to eliminate disallowed options. The same logic can be added to this module fix the issues. Let me know if you need/want a patch:
function hook_form_file_entity_add_upload_alter(&$form, &$form_state) {
// The scheme selection step
if ($form['#step'] == 3) {
// See if the available schemes for this field are present
if (isset($form_state['build_info']['args'][0]['schemes'])) {
// Iterate the schemes for this field and remove options that are
// not available.
foreach ($form_state['build_info']['args'][0]['schemes'] as $scheme => $active) {
if (!$active) {
unset($form['scheme']['#options'][$scheme]);
}
}
// If there is only one scheme left, default to it
if (count($form['scheme']['#options']) == 1) {
$form['scheme']['#default_value'] = key($form['scheme']['#options']);
}
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#9 | file_entity-remove-disallowed-schemes-2217841-09.patch | 2.93 KB | Devin Carlson |
#5 | file_entity-3661d8b-2217841-05.patch | 823 bytes | jhedstrom |
#4 | file_entity-remove-disallowed-schemes-2217841-04.patch | 882 bytes | jhedstrom |
#4 | interdiff.txt | 690 bytes | jhedstrom |
Comments
Comment #1
mstef CreditAttribution: mstef commentedBetter alteration:
Comment #2
valderama CreditAttribution: valderama commentedThanks! This snippet works nicely.
It might be nice to skip this page completely if only one option is available.
Comment #3
jhedstromI was seeing this issue on a site where I had the scheme selection turned off completely. This worked great for files that were supposed to be stored in the default scheme. However, on a field where the only available scheme was not the default, it still tried to move the file to the default scheme.
The attached patch iterates through the available schemes for a given instance of the media browser, and removes any not available.
Comment #4
jhedstromThe last patch sometimes didn't work since disallowed schemes might not even be in the build arguments.
Comment #5
jhedstromThis is the same as the patch in #04, but against a version of file_entity/media that is more stable (a few commits after last alpha). The one in #04 is the one to test, this is out of necessity since upgrading to later media/file entity is not working smoothly.
Comment #7
jhedstrom#05 failed to apply the patch (as it should have). Sorry for the noise.
Comment #8
Yazzbe CreditAttribution: Yazzbe commentedapplied #4 with no luck ...
I have a media field that specifies files to be uploaded to a private folder. But when I attach a file to the media field, it gets uploaded to the (unprotected) default location.
However, when clicking the edit button of the file afterwards, I can select 'private folder' and move the file over to the private location.
I'm can't write patches (themer). But I can help review and test solutions.
Drupal 7.31
File entity 7.x-2.0-alpha3+37-dev
Media 7.x-2.0-alpha3+114-dev
Comment #9
Devin Carlson CreditAttribution: Devin Carlson commentedA patch to take any restricted schemes from field instance settings into account when adding a file through the file upload wizard.
For the related Media issue, see #1289680: Widget does not respect Allowed URI Schemes.
Comment #10
Dave ReidTested and committed #9 to 7.x-2.x.