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.
Is there a way for attachments to display on screen rather than giving the user a download prompt when they are directed to the node/NID/attachment/newest filepath?
Comment | File | Size | Author |
---|
Comments
Comment #1
_vid CreditAttribution: _vid commented@vee
Here's how I did it. I added this code to force load the 'preferred' link when the node is accessed (for non-admins).
+edit: I added an li item to the list of links displayed showing admins the full path they can use as a link.
$attachment_links = "<div class=\"item-list\"><ul><li class=\"first last\">Preferred version with clean url:".l(url($node->path, $options), $node->path)."</li></ul></div>\n".$attachment_links;
This should probably be done with an override to attachment_links_build_links($node).++edit: I replaced l($preferredLink,$preferredLink) with l(url($preferredLink, $options),$preferredLink) to display the fully qualified url to the admin.
To do this I added this code before the current code in attachment-links.tpl.php.
I'd prefer to do it with a custom module or template overrides but I'm just getting a grip on that and couldn't manage to hook the right functions.
In addition it would be nice to alter the form to add an option to turn this functionality on or off and lastly, set the permission that would determine the behavior (rather than just hard coding 'administer nodes'). Perhaps picking from available roles (admin, authenticated, etc...) would make sense as well.
But it would take a better Drupaler than I to do that.
If these seem like valuable additions maybe we could add them as feature requests.
Comment #2
Todd Nienkerk CreditAttribution: Todd Nienkerk commentedThis is a feature in Drupal core. Just check off the "List" box next to each attachment you want listed at the bottom of a node.
Is what you're asking for a display of the download links (newest/preferred)? Have you tried the official 6.x-1.0 release?
Comment #3
nunami CreditAttribution: nunami commentedI am trying out Attachment Links and I think Vee is referring to when you use the links provided by the module it will cause the browser to download the file rather than opening it.
The site I am working on has users that need to update PDFs which are linked on many pages. Rather than updating the links individually, it would be easier to use a module like Attachment Links which will link to the newest document version. However, when a user clicks on the "newest" link it asks them to download the file rather than opening it up in the browser.
So, if the "newest" link is used in FCK, is there any way to have that link open the PDF/Doc/PPT rather than asking the user to download it?
Thanks,
Nu
Comment #4
Todd Nienkerk CreditAttribution: Todd Nienkerk commentedIs this not a browser setting? Shouldn't the browser decide (or give the user the option to decide) whether a file is opened or saved?
Comment #5
markabur CreditAttribution: markabur commentedIn Safari I can see the difference in behavior if I list the file in addition to displaying the attachment links. If I click the regular file link, the pdf is displayed in the browser like I'm accustomed to, but if I click the attachment link, the file is always downloaded immediately, with no dialog.
In Firefox I'm offered an "Opening attachment" dialog either way.
I find that if I comment-out lines 242 and 243 of attachment_links.module, then Safari behaves as expected and Firefox doesn't change. But both of them lose the filename.
Comment #6
markabur CreditAttribution: markabur commentedFiddled around with this, and I get the behavior I want by using drupal_goto() instead of the file_transfer() stuff.
Comment #7
Todd Nienkerk CreditAttribution: Todd Nienkerk commentedmarkabur: Interesting. We'll need to investigate whether what you proposed is a better method.
Comment #8
_vid CreditAttribution: _vid commentedJust a follow up to my comment above (#1).
I've been using this method for the last year & 1/2 on several sites and it works great.
Anonymous users are redirected and admins are not. Instead they are presented with the list of links and the standard admin tabs.
I'm currently using Attachment Links 6.x-1.1.
Recently I found out that using drupal_goto on anonymous users can keep the cron process from completing. *Thanks to dev-art.net/en/article/solving-cron-run-exceeded... for the solution.
So I updated the copy of attachment-links.tpl.php in my theme to check if the script running is cron.php before drupal_goto.
Here's the full code for my theme's attachment-links.tpl.php:
I'm happy to make this a patch if this option is inline with the direction of the module.
Comment #9
Todd Nienkerk CreditAttribution: Todd Nienkerk commentedGiven the problem with
drupal_goto()
and the complexity of the resulting workaround, I think we should dig deeper into the solution provided by markabur in #5. I suspect, however, that changes to the headers will break IE.Changing the issue title to reflect the clarified scope of this issue.
Comment #10
_vid CreditAttribution: _vid commentedWorks for me.
Though; I think think there's two different issues here. Perhaps we should split them apart.
markabur is addressing the browser delivery of the attachment.
I want to address how the node is presented to anonymous vs. administrative users. Here's what I would like to see:
What are you thoughts on that?
Comment #11
markabur CreditAttribution: markabur commentedI am kind of keeping an eye on this, though I don't have access to the site I used it on anymore. I hope they aren't having cron troubles because of drupal_goto().
Since D7 has the cron queue, I wonder if drupal_goto() only causes a problem on D6?