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.
Attached are patches to enable a new "New Window" checkbox to appear similar to how the "list" option functions and is coded. By checking the box, anyone who clicks on the linked file will open that file in a new window. This is helpful for PDF files and other text documents.
I'm still trying to get patches to be created properly on my Windows system, so if there are any issues, let me know and I'll fix and re-patch.
Comment | File | Size | Author |
---|---|---|---|
filefield-new_window.module.txt | 4.89 KB | pcorbett | |
filefield-new_window.install.txt | 636 bytes | pcorbett |
Comments
Comment #1
jpetso CreditAttribution: jpetso commentedThanks for the patch. From a technical point, you succeeded with generating a proper patch, except that you should try not to use tabs and trailing whitespace in Drupal style code... but that's just a cosmetic issue.
As for the actual contents of the patch, I'm slightly sceptical about one more checkbox if it isn't absolutely necessary. ("List" is too much already imho, but necessary.) And in your case, I think it isn't. How about the following, different approach:
...and that's it - just overriding theme_filefield() with the necessary changes in your theme. Explanation: As theme_filefield() gets the $file parameter, you also have access to $file['filemime'] which contains the MIME type of the respective file. If the file type is one of those that you want to open in a new window, you get it automatically for each of those files and without additional checkboxes or database additions. I think this is a better solution (and more maintainable too). The only drawback is that you can't decide on a file-for-file basis, but that would be a bad idea from a usability point of view anyways.
As always with my example code, this is completely untested and may not work (but could). Hope this helps.
Oh, and thanks for the l() suggestion in theme_filefield() instead of hardcoding '<a href="...">', I'll incorporate that even though I have to reject the rest of your patch because of the concern mentioned above. But don't let yourself be fooled by that, it's good work nonetheless :)
Comment #2
hillaryneaf CreditAttribution: hillaryneaf commentedI too am interested in this functionality. I tried the theme override above but it doesn't work in 2.3rc4 and the icons disappear.
Comment #3
cgjohnson CreditAttribution: cgjohnson commentedI too am interested in this. Does this php code go into my theme's template.php, or somewhere else? I added it to the template.php and it doesn't seem to work -- maybe because I'm using Views?
Comment #4
dppeak CreditAttribution: dppeak commentedTake a look here for an updated solution http://drupal.org/node/301234