Recently implemented hook_link_alter to open all external links in a new window. This was done on Drupal 8.5.X and worked without issues. The implementation tested is the URL was external and if so, added the target="_blank" attribute.

Prior to moving code to production, Drupal core was updated to 8.6.3 (modules as well). QA on the site revealed that some external links were no longer opening in a new window/tab. Links such as those going to twitter or facebook had no issues. The links that were not being recognized were part of a third party integration and had the domain name included.

Example:
-- Domain Name: mysite.com
-- Links not being recognized as external: mysite.thirdparty.com/contact or mysite.thirdparty.com/form

It seems that when the site name appeared in the subdomain Drupal was not recognizing it as external. I verified this by printing out the link text for those links that Drupal deemed external ->

function hook_link_alter(&$variables) {
if ($variables['url']->isExternal()) {
debug('link text: ' . $variables['text']);
}
}

Links of the pattern [domain_name].thirdparty.com did not appear in debug statement.

Comments

guerinteed_mike created an issue. See original summary.

cilefen’s picture

As this is Drupal\Core\Url::isExternal the issue could be mis-categorized as the link module and may be "base system" instead.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dcam’s picture

Component: link.module » base system
Status: Active » Postponed (maintainer needs more info)
Issue tags: -external URL +Needs steps to reproduce

Moving to the base system per #2.

But furthermore I can't reproduce the issue. If I enter URLs like https://mysite.com or https://mysite.thirdparty.com they are always considered to be external, which is how the Url class works. If I leave off the schema (https://), then I can't even save a link field due to validation errors. Therefore, this problem needs better steps to reproduce starting from a fresh install of Drupal Core.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
Issue tags: +Bug Smash Initiative

There has been no discussion here for 7 years. Including no reply for more information asked for 8 months ago.

Therefor, closing this issue. If you are experiencing this problem provide steps to reproduce the issue starting from "Install Drupal core" and set the status to 'Active'.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.