CCK Assets (http://drupal.org/node/209387) don't seem to work as I would expect them to work, for file formats such as PDF and TXT documents.

Can someone explain how to get the "Download this file" link to appear on a node with an asset field. It would be even better if the caption for the asset simply was a URL to the document. It isn't clear how these links are generated automatically for certain file formats.

Any help on this matter would be greatly appreciated.

Thanks,

Comments

wmostrey’s picture

Assigned: Unassigned » wmostrey
Category: support » bug

This actually looks like a bug. A link to the file should indeed be provided if no other means to view/handle it is available.

jmlane’s picture

I changed the code below, starting at line 872 of asset.module, as a temporary fix to display download links for my assets attached to a node type, but I think the way the field items are generated in Asset needs to be looked at (should definitely not be using 'preview' for op, in my opinion):

    case 'preview':
      switch ($attr['format']) {
        case 'image' :
          return theme('image', file_create_path($asset->filepath), '', '', array('width' => '100'), false);
        case 'link' :
          return theme('asset_render_default', $asset);

I added the theme('asset_render_default', $asset) to the last return, to generate the links.

I am fairly new to the contrib development aspect of Drupal, so I am sure I understand correctly what is happening in the hook_asset_formatter() function, but I think perhaps there should be a unique output for the field items when viewed on a page view or how they are previewed in the Wizard. Also it might be useful to have a more compact format for table or list Views (maybe the same as what should be seem on the page view, if compact enough).

Any feedback or additional explanation would be greatly appreciated. I am willing to do the coding on these items, I am just not sure how to proceed.

wmostrey’s picture

Hey Jonathan,

The "preview" name might be a bit oddly chosen but it comes from asset_preview, the function that is called to generate a "preview" of the file before actually viewing the original size. So this could be the imagecached version of an image, a medium-sized video, ... In the case of an unknown format a link is displayed. So even if this isn't really a preview, it is still the preview $op.

Thanks a lot for your code. Trying it out I notice that the filename appears two times now: once as a link and once as a regular string. The best way would be to just display the link of course. I'll continue on this, unless you come up with a patch of yourself of course.

This might be a good resource for continuing your steps as a contributor: http://drupal.org/patch/create. Your help is highly appreciated!

wmostrey’s picture

Status: Active » Needs work
wmostrey’s picture

Status: Needs work » Reviewed & tested by the community

Hey Jonathan,

I made some more progress in this and fixed the issue. About the filenames appearing twice: one was the actual link and the other was the caption, which by default is the same as the link. I updated theme_asset_render_default (asset.module) to display the filename instead of the caption, like this:

function theme_asset_render_default($asset) {
  return '<a href="'. url($asset->url) .'" class="asset">'. $asset->filename .'</a>';
}

This will be committed tonight. Thanks a lot for reporting and contributing!

wmostrey’s picture

Status: Reviewed & tested by the community » Fixed

This has been committed: http://drupal.org/cvs?commit=101719

jmlane’s picture

Cool, I will check the changes.

Are the functions that provides that caption and copyright theme override-able? I am not sure I like the way these render, yet I can understand how it is best to leave that up to the individual user to change the output to something different if they choose to do so via theme function overriding.

Thanks for all your help and support!

Jon

Anonymous’s picture

Status: Fixed » Closed (fixed)

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