Issue

The recent bug fix for external files being broken when using the Download link formatter (#2152323: Download formatter does not work with external files like youtube, vimeo and etc.) makes the resulting link use the filename instead of the custom link text set in the administrative UI.

Cause

After examining the code, this is a result of using file_entity_file_is_local() in line 316 of file_entity.field.inc to skip over the external file. This results in not setting $element and using the last resort of theming the link using theme_file_link() - which happens in field_entity.file_api.inc line 266.

Solution

Instead of opting to use the theme_file_link() fallback instead of theme_file_entity_download_link(), I propose that the module move the local file detection into theme_file_entity_download_link() and simply serve up a different $url for the link based on if it's external or internal. The reason for this is because like theme_file_entity_file_link(), theme_file_entity_download_link() is not very different from theme_file_link(). With a few lines of code, we can modify theme_file_entity_download_link() to support external files instead of pre-empting it.

Comments

pianomansam’s picture

Status: Active » Needs review
StatusFileSize
new1.77 KB

Here is a patch that does what I suggest: It moves file_entity_file_is_local() to theme_file_entity_download_link() and allows the custom download link to still apply.

dave reid’s picture

Title: External files using download formatter loose custom link text » External files using download formatter lose custom link text
dave reid’s picture

Hrm, I'd rather we still route remote files through our page callback, so maybe we can fix this in the download page callback itself and redirect to the remote URL instead of doing a file_transfer().

dave reid’s picture

StatusFileSize
new1.44 KB

Wrong patch.

pianomansam’s picture

Dave, that's a really nice approach since we can still count downloads and such.

dave reid’s picture

Status: Needs review » Fixed

Committed #4 to 7.x-2.x.

  • Dave Reid committed ad4a5fb on 7.x-2.x
    Issue #2276437 by Dave Reid, pianomansam: Fixed external files using...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.