I've been trying to come up with a solution for hiding the upload widget when other sources are enabled, with little luck. The best I've been able to accomplish was to hide "Upload" from the widget's sources list, but that's it.
I know it can be achieved with CSS, but I need something more radical.
Here's a possible use case:
- say I have two node types: Gallery (used to upload images, with per-user upload limits) and Page (a regular page, with the possibility to reference existing images via the reference source
- users should be allowed to upload only on the Gallery node type, so that maximum file upload limits can be honored.
I know Filefield Sources relies on the upload widget, which is why in my attempts I've always preserved all references to the validation processes and such, but the best I end up with is an unusable upload widget (unusable because it lacks an "Upload" button). I'm currently out of ideas on how to remove the file input field and make one of the secondary sources the default source. I've also looked into Filefield's theme_filefield_widget_file(), but with little or no luck—I'm not sure it's the right way to go, either.
Any help will be much appreciated.
Comment | File | Size | Author |
---|---|---|---|
#1 | noupload.inc_.txt | 1.1 KB | antiorario |
#1 | filefield_sources-879902.patch | 1.56 KB | antiorario |
Comments
Comment #1
antiorario CreditAttribution: antiorario commentedI've given up (for the time being) on the idea of completely hiding the upload widget, and I've settled with disabling it. I've created a new source (although it's a source only by name, not by function) that does the following:
Since this is not an actual source, it makes no sense for it to have its own entry in the sources list on the node edit form. Hence, the source has no label. This, however, means that there will be an empty spot in the sources list. To overcome this problem without breaking existing functionality, I propose an appropriate modification to
theme_filefield_sources_list()
, to show a source in the list only when the source has a label attribute.In addition to this, I don't think there should be an "Upload" source in the widget's sources list when uploading is disabled, so I propose a further modification to the same function—again, this doesn't break any existing functionality. Here's what it would look like:
Attached: the proposed patch to filefield_sources.module (1.2) and the proposed noupload.inc source file.
Comment #2
sirviejo CreditAttribution: sirviejo commentedAnd how about disable the upload widget for a specific role?
Comment #3
antiorario CreditAttribution: antiorario commentedsirviejo: it's definitely something worth considering, but that would mean giving a specific source (or pseudo-source, as in this case) a role-based setting while leaving the other sources without this option.
quicksketch can correct me if I'm wrong, but I think if we were to give the sources the option of role-based visibility, it should be accomplished via a module-wide hook that any source (including those provided by external modules) should be able to tap into. However, for what I've understood from older issues, I'm not sure that's the direction this module is supposed to be going.
Comment #4
arlinsandbulte CreditAttribution: arlinsandbulte commentedIf #877452: Enable uploading and deletion through IMCE is acheived, I think we could just allow the default upload widget to be disabled and allow IMCE to fill in.
Then, the excellent IMCE profile & permission settings could be used.
Comment #5
antiorario CreditAttribution: antiorario commentedThis issue is not related to IMCE, and my proposal should work independent of IMCE.
Comment #6
jenlamptonThis looks like a duplicate of #742134: I would like to disable the default "Upload" source in favour of using the upload option within IMCE ?
@arlinsandbulte: Note that using IMCE poses a huge security risk
Comment #7
arlinsandbulte CreditAttribution: arlinsandbulte commented@jenlampton: Correct me if I am wrong, but yes, IMCE might pose a security risk if configured improperly or the wrong permissions are given to untrusted users.
Comment #8
antiorario CreditAttribution: antiorario commented@jenlampton I don't think this is necessarily a duplicate of the issue you're referring to. Set aside any security concerns, my initial post had nothing to do with IMCE, while the other issue has everything to do with it. Also, while I do consider both solutions to fall into the category of tweaks, I'm trying to find something that can achieve the goal system-wide, without resorting to hiding content via CSS (which is theme-dependent and doesn't prevent users from using the upload widget if they want to).
Please, let's not close issues only because they sound like something else.
Comment #9
antiorario CreditAttribution: antiorario commentedI'm closing this, because I've just released a module that hooks into FileField Sources and achieves this exact goal, including the theme function override I suggested at #1.
I'm marking it as fixed because this is, in fact, a solution. FileField Sources Disable Upload: http://drupal.org/project/filefield_sources_noupload (As usual, the dev version should be available later.)
Comment #10
quicksketchReopening this as a potential feature for inclusion directly in FileField Sources. I've said in the past that this was not possible, but I've clearly been proven wrong. Let's think about this as a patch to FIleField Sources instead of an additional module.
Comment #11
quicksketchComment #12
antiorario CreditAttribution: antiorario commentedquicksketch, it seems I missed your response on this issue. Of course it would be much better if it were part of FileField Sources—any progress on that?
Comment #13
dazweeja CreditAttribution: dazweeja commented@antiorario, I added some JS to your module so that the interface was cleaner for users. Obviously, it could be cleaner still if it was integrated directly into Filefield Sources.
#1177230: Added JS so that first file source is automatically displayed
Comment #14
antiorario CreditAttribution: antiorario commentedNew dev of FileField Sources Disable Upload will include dazweeja's contribution.
Comment #15
iNade CreditAttribution: iNade commentedIs there any port for D7 module ? Just asked in the filefield_sources_noupload project issue queue.
Comment #16
iNade CreditAttribution: iNade commentedComment #17
quicksketchLet's merge this with #932994: Filefield source "Remote URL" (or any other) set as default option (aka Disable Upload option), which suggests making the same change.