Open file, etc. links in a new tab/window

By デビッド, 24 June, 2016

JS code for enabling file field links to open in a new window:

https://www.drupal.org/node/301234

JS code for enabling file field links to open in a new window:

/** * Implements hook_preprocess_HOOK(). */
function THEME_preprocess_file_link(&$variables) {
  // Add target _blank attribute to all file links.
  $file = $variables['file'];
  $url = file_create_url($file->uri->value);
  // Use the description as the link text if available.
  if (empty($variables['description'])) {
    $link_text = $file->filename->value;
  }
  else {
    $link_text = $variables['description']->__toString();
  }
  $link = '<a href="'.$url.'" type="'.$file->filemime->value . '" length="' . $file->filesize->value . '" title="' . \Drupal\Component\Utility\Html::escape($file->filename->value) . '" target="_blank">' . \Drupal\Component\Utility\Html::escape($link_text) . '</a>';
  $variables['link']->setGeneratedLink($link);
}

 

Assigned to
Status
Closed
Priority
Minor
Category
Feature request
Stitch from Lilo & Stitch

デビッド

8 years ago

Fixed with the external links module for links - just need to implement the js for files.

Timbers Space Gordillo Legal You Pick Farms Tomo Arigato All Fur Love BehaveNet Dowell Media