Hi,

I'd like to request a feature to set the link target to "Open link in a new tab or window".

And also, to set the "rel attribute".

Thank you for your attention.

Bryant

Comments

badrun’s picture

Issue summary: View changes
gbelot2003’s picture

I did it on the easy and (not recomended) way, override the module, on the line 293, there is the url_field_formatter_prepare_view function, just add this code

<?php
function url_field_formatter_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $displays) {
  foreach ($entities as $id => $entity) {
    $settings = $displays[$id]['settings'];

    foreach ($items[$id] as $delta => &$item) {
      // If the formatter is configured to add rel="nofollow" to links, then
      // add them here.
      if (!empty($settings['nofollow'])) {
        $item['options']['attributes']['rel'] = 'nofollow';
        $item['options']['attributes']['target'] = '_blank'; // adding _black atribute
      }
    }
  }
}
?>

This feature is a "must" on this module, I dont understand why they didn't incluide it at first....

Owl Solo’s picture

gbelot2003,

Thank you for the code. I couldn't get it to work.

I just wanted to lend my voice in support of adding this feature! Please add!!!

nitinsp’s picture

In content type manage display tab added checkbox under url filed for target="_blank". If user enable this checkbox and update the setting of url field and save mange display setting all url in perticular content will be open in new tab.

nitinsp’s picture

Status: Active » Closed (fixed)
nitinsp’s picture

nitinsp’s picture

Status: Closed (fixed) » Needs review

Status: Needs review » Needs work
nitinsp’s picture

Status: Needs work » Needs review
StatusFileSize
new1.68 KB

In content type manage display tab added checkbox under url filed for target="_blank". If user enable this checkbox and update the setting of url field and save mange display setting all url in perticular content will be open in new tab.

Status: Needs review » Needs work

The last submitted patch, 9: url-Open_link_in_a_new_tab_or_window-2366021#-8-7.x-1.x.patch, failed testing.

nitinsp’s picture

Status: Needs work » Needs review
StatusFileSize
new1.57 KB

Updated formatting, please review the latest patch #11.

nitinsp’s picture

correct the formatting, please review the latest patch #12.

nitinsp’s picture

Added some missing code and correct the formatting, please review the latest patch #13.

nikunjkotecha’s picture

Status: Needs review » Reviewed & tested by the community
nikunjkotecha’s picture

jcnventura’s picture

Note that #1914126: Add optionale link attribute: target implements this in a more generic fashion, instead of only supporting "_blank", it also supports "_self", "_parent" and "_top".