It's very convenient to be able to write a template function to modify the the options used to create the links for uploaded files. I wrote the following:

function masslegal_upload_attachments($files,$options = null) {
  // all attachment links should open in a new page. 
  $options['attributes'] = array('target' => '_blank');
  return itweak_upload_upload_attachments($files,$options);
}

Because I wanted links to open in a new window.

However - itweak_upload_upload_attachment only pays attention to the $options argument if the file is to be previewed :(.

I'm not sure why that is. I've attached a patch to change that behavior.

jamie

Comments

iva2k’s picture

Status: Active » Needs review

Great! Can community review and post results here? If there are no problems, I can commit quickly.

nessunluogo’s picture

I was looking for some solution to open attachments with target="_blank", using this great module.
So I patched the file, added the code in my template.php (changeing the name of the function, obioviusly)... and it worked like a charm.

iva2k’s picture

Status: Needs review » Needs work

I looked into the patch, and found the logic that I do not fully understand:

-        'data' => l($text, $href, ($options && $file->access && (isset($file->preview) || _itweak_upload_isimage($file))) ? $options : array()),
+        'data' => l($text, $href, ($options && $file->access || _itweak_upload_isimage($file)) ? $options : array()),

The original logic does not pass options when user has no access permission ($file->access), and then the file either needs to have a preview, or should be an image. With new code, image files ignore file->access, and ignore empty options. In case of empty options the l() function will throw an error (this is the reason for passing array() instead of empty variable $options).

I am acknowledging that $file->access use logic here is questionable, but I copied that code from core upload module. I can propose the following code instead:

-        'data' => l($text, $href, ($options && $file->access && (isset($file->preview) || _itweak_upload_isimage($file))) ? $options : array()),
+        'data' => l($text, $href, ($options && $file->access && (isset($file->preview) || _itweak_upload_isimage($file) || isset($options['custom']))) ? $options : array()),

Then your custom override code can set $options['custom'] = TRUE; and options will be passed in. If there is no custom code, the original logic is preserved.

iva2k’s picture

Status: Needs work » Fixed

I checked the proposed modification (...||isset($options['custom']) to 6.x-2.x-dev. I have no way to verify except that it does not break the original functionality.

Please try it (you need to modify your code to set $options['custom'] = TRUE), and reopen if it does not resolve your problem.

Status: Fixed » Closed (fixed)

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

BigEd’s picture

Hi did this ever get added to the module or is this still in a proposed patch?

I am looking for a way to open the files in TARGET = "_blank" #

Thanks

iva2k’s picture

Read #4 - one mod is in 6.x-2.x-dev as of October 2010.
BTW It's pointless to comment on an issue closed a year ago - most people won't see it with default filters.

BigEd’s picture

Ok point taken i will make a new post, did think of that after i had posted lol.

Thanks for advice anyhow.