From 588b159dbd3fe01980df732d0f06982611cd7b16 Mon Sep 17 00:00:00 2001 From: naomi Date: Mon, 7 May 2018 18:31:24 +0200 Subject: [PATCH] Added hook to open external menu links in new tab --- opencase.module | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/opencase.module b/opencase.module index b779e84..d5b6739 100644 --- a/opencase.module +++ b/opencase.module @@ -7,6 +7,18 @@ use Drupal\Core\Routing\RouteMatchInterface; + +/** + * Implements hook_link_alter + * + * Makes menu items that are external links open in new tab. + */ +function opencase_link_alter(&$variables) { + if ($variables['url']->isExternal()) { + $variables['options']['attributes'] = ['target' => '_blank']; + } +} + /** * Implements hook_preprocess_page_title *