Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fluxyster created an issue. See original summary.

brucelee1985’s picture

NWOM’s picture

Status: Active » Needs review
Issue tags: -link target _blank

Setting to needs review and removed the tags (See Issue Guidelines). Thanks for the patch. I hope this gets added to the module.

Status: Needs review » Needs work

The last submitted patch, 2: display_add_link_target-2691943.patch, failed testing.

NWOM’s picture

Here is an updated patch that fixes a few white space and consistency issues. Please review.

badjava’s picture

There are still some spacing issues near the bottom of #5.

$uri['options']['attributes']['target']=$display['settings']['target'];

should be

$uri['options']['attributes']['target'] = $display['settings']['target'];
caminadaf’s picture

Status: Needs work » Needs review
FileSize
2.05 KB

I've reviewed the diff using phpcs with Drupal and DrupalPractice standards, not it should be OK.

chinmay_p’s picture

Status: Needs review » Reviewed & tested by the community

Tested the patch against version 7.x-1.1.Upon selecting entity reference,It gives option to add target. When "_blank" is added in target field,it gets open in new tab.

This patch works as expected.

The last submitted patch, 5: display_add_link_target-2691943-4.patch, failed testing.

hexblot’s picture

Title: Need to display field with link with attributes target with _bank » Need to display field with link with attributes target with _blank
FileSize
2.22 KB

Started using the patch in #7 on two sites, and it works wonderfully. A small change made by me in order to help novice site builders is to abstract the textfield in favor of a simple select control (New Window vs Same Window instead of a blank text field), it should help with usability.

It is heavily based on the patch in #7 (just FAPI changes, and display).

spotzero’s picture

Status: Reviewed & tested by the community » Needs work

Actually, patch #7 has the valid behaviour. See: http://www.w3schools.com/TAGS/att_a_target.asp
Link targets can be any string when you're working with named frames.

What patch #7 needs is help text. ;)

The last submitted patch, 10: display_add_link_target_with_select.patch, failed testing.

oleg chemerys’s picture

The issue still exists in 1.4 version, so I've updated the patch #7.

Arlina’s picture

Version: 7.x-1.1 » 7.x-1.5
Status: Needs work » Needs review
FileSize
1.76 KB

Updated the patch for version 7.x-1.5.

Chris Matthews’s picture

Version: 7.x-1.5 » 7.x-1.x-dev
Assigned: brucelee1985 » Unassigned

Unassigned @brucelee1985

markusd1984’s picture

thanks @ Arlina, I used the code and made something similar for the entity registration module, and also just now changed it to use a checkbox instead of a text field since usually only the "_blank" target type is of real practical use and thus no need for custom entry i supposes.

 Registration Link Formatter Link Target checkbox

https://www.drupal.org/project/registration/issues/3156687#comment-13732212

Code below, may need to be adjusted for ER.

function entityreference_field_formatter_info() {
'target' => FALSE,
function entityreference_field_formatter_settings_form(

  if ($display['type'] == 'entityreference_label') {
$element['target'] = array(
      '#title' => t('Open in new tab (link target _blank)'),
      '#type' => 'checkbox',
      '#default_value' => $settings['target'],
    );
function entityreference_field_formatter_view(

if ($display_link) {
          $uri = entity_uri($target_type, $item['entity']);

if (isset($settings['target']) && $settings['target'] === 1){
$uri['options']['attributes']['target'] = '_blank';
}
else 
{
$uri['options']['attributes']['target'] = '';
}
       $result[$delta] = array(
          '#theme' => 'entityreference_label',
          '#label' => $label,
          '#item' => $item,
          '#uri' => $uri,
//
'options' => $uri['options'],
//
          '#settings' => array(
            'display' => $display['settings'],
            'field' => $field['settings'],
          ),
        );

The below needs more review to probably make checkbox work with ER.

function theme_entityreference_label($vars) {

  $label = $vars['label'];
  $settings = $vars['settings'];
  $item = $vars['item'];
  $uri = $vars['uri'];
//
$uri_options = array('attributes' => array ('target' => $variables['options']['attributes']['target']));
//
  $output = '';

  // If the link is to be displayed and the entity has a uri, display a link.
  // Note the assignment ($url = ) here is intended to be an assignment.
  if ($settings['display']['link'] && isset($uri['path'])) {

//patch to add link formatter target https://www.drupal.org/project/entityreference/issues/2691943#comment-12445292
    if ($settings['display']['target']) {
//      $uri['options']['attributes']['target'] = $settings['display']['target'];
      $uri_options = $settings['display']['target'];
    }
//    $output .= l($label, $uri['path'], $uri['options']);
    $output .= l($label, $uri['path'], $uri_options);
  }
}