How to leverage the "Open all external links in a new tab" setting in site customizations

Ah right, I overlooked the “user” part :sweat_smile: sorry

It’s not much different to use the user setting, you’d just have to change the first two constants to reference the user:

// set up the user and target variable:
const user = api.getCurrentUser()
const target = user?.user_option?.external_links_in_new_tab ? "_blank" : ""

and then everything else would be the same.

If this were to work more like core, we’d check if the user exists, and if they don’t, fall back to the site setting:

// set up the user, siteSettings, and target variable:
const user = api.getCurrentUser()
const siteSettings = api.container.lookup('site-settings:main');
let target = siteSettings.default_other_external_links_in_new_tab ? "_blank" : ""; 

if (user) { // if the user exists, set the target based on the user option
 target = user.user_option?.external_links_in_new_tab ? "_blank" : ""
} 

// modify the if statement where the link is created to use the target variable: 
if (userFields && userFields[userFieldId]) {
  const url = "http://myawesomewebsite.com/user/" + userFields[userFieldId];
  const link = `<a href="${url}" target="${target}">${url}</a>`;
  return Ember.Object.create({ link, name: externalUserIdField.get('name') });
} else {
  return null;
}
2 Likes