Issue #3608723: Add a setting to control the target="_blank" attribute

Closes #3608723

Problem

The target="_blank" attribute was forced onto external links with no way to turn it off:

  • In the filter, ExternalLinkA11yFilter::process() added target="_blank" to any in-scope external link, gated on the external_url detection setting.
  • In the formatter, ExternalLinkA11yFormatter::viewElements() always added target="_blank" to external links with no setting at all.

There was no way to keep the accessibility enhancements (the visually hidden "Open in new window" message, rel attributes) on external links without also forcing them to open in a new window, which is a debated accessibility practice (WCAG technique G200 advises against opening new windows without warning the user).

Changes

  • Add a dedicated add_target_blank setting to both the filter and the formatter, defaulting to TRUE so existing sites keep their current behavior.
  • The target="_blank" attribute is now added only when add_target_blank is enabled; detection (external_url / target_blank) is now purely about which links are in scope.
  • Filter: the "Open in new window" message is now shown only when the link actually opens in a new window (has or gains target="_blank"), so the message can never be inaccurate. Renamed the internal scope flag from $is_opening_in_new_window to $in_scope to reflect its real meaning, and corrected the external_url field wording (it no longer implies it adds target).
  • Config schema updated for both the filter and formatter settings.
  • Kernel test coverage: attribute added when enabled, not added when disabled (and the message suppressed with it), and the message still shown for links that already carry target="_blank".

Note

This MR is built on top of the fix in #3608714 (it shares that commit) because both change process(); please merge #3608714 first, then this one.

Behavior change: the formatter previously always forced target="_blank" on external links; it now respects the new setting (default on, so no change unless disabled).

Merge request reports

Loading