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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jpetso’s picture

Status: Needs review » Closed (won't fix)

Thanks 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:

function phptemplate_filefield($file) {
  if (user_access('view filefield uploads') && is_file($file['filepath']) && $file['list']) {
    $path = ($file['fid'] == 'upload')
            ? file_create_filename($file['filename'], file_create_path($field['widget']['file_path']))
            : $file['filepath'];

    $url = file_create_url($path);
    $desc = $file['description'];
    $attributes = array();

    $new_window_mimetypes = array(
      'application/pdf',
      'text/plain',
      ...
    );
    if (in_array($file['filemime'], $new_window_mimetypes)) {
      $attributes['target'] = '_blank';
    }
    return l($desc, $url, $attributes);
  }
  return '';
}

...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 :)

hillaryneaf’s picture

Version: 5.x-2.2 » 5.x-2.3-rc4

I too am interested in this functionality. I tried the theme override above but it doesn't work in 2.3rc4 and the icons disappear.

cgjohnson’s picture

I 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?

dppeak’s picture

Version: 5.x-2.3-rc4 » 6.x-3.3

Take a look here for an updated solution http://drupal.org/node/301234