Open Menu Link In New Browser Tab/Window I am having a problem with opening a menu link defined in a module.links.menu.yml in a new browser tab or window. Code for the link:

mymodule.mm_google:
  url: 'https://google.com/'
  parent: mymodule.admin_mm.external_index
  description: 'Search Engine'
  title: 'Google'
  options:
    attributes:
      target: _blank


I am working with Drupal core 8.2.4 8.2.5 and the link currently works except for opening a new browser tab or window.

Update:
The links are opening in a new tab/window when rendered by the Toolbar/Admin Toolbar modules but not when rendered and displayed by  admin overview controller \Drupal\system\Controller\SystemController::overview. The controller will also not render included classes for the anchor element.
Doing a review of how \Drupal\system\Controller\SystemController::overview builds an Admin Overview page and I found that template_preprocess_admin_block_content was only constructing each link item as an array values that did not include a URL object. While menus built by the admin Toolbar did. The importance of the URL (Drupal\Core\Url) instance being generated is that it includes an Attributes (Drupal\Core\Template\Attribute) instance that Twig can use to render an item's HTML attributes.

The fix:

The template_preprocess_admin_block_content function can be located in a custom module but, there is the requirement to add an overriding template file in the admin theme so it is best to locate the function a custom admin theme. (It is important that you remember the difference between your front-end theme and your admin theme as they are not the same)

/themes/myadmintheme/myadmintheme.theme

/**
 * Implements template_preprocess_admin_block_content().
 */
function myadmintheme_preprocess_admin_block_content(&amp;$variables) {
  if (!empty($variables['content'])) {
    foreach ($variables['content'] as $key =&gt; $item) {
      $variables['content'][$key]['attributes'] = new Attribute(empty($item['options']['attributes']) ? array() : $item['options']['attributes']);
    }
  }
}



/themes/myadmintheme/templates/admin-block-content.html.twig

{#
/**
 * @file
 * My admin theme implementation for the content of an administrative block.
 *
 * Uses unordered list markup in both compact and extended modes.
 *
 * Available variables:
 * - content: List of administrative menu items. Each menu item contains:
 *   - url: Path to the admin section.
 *   - title: Short name of the section.
 *   - description: Description of the administrative menu item.
 *   - attributes: HTML attributes of the administrative menu item.
 * - attributes: HTML attributes to be added to the element.
 * - compact: Boolean indicating whether compact mode is turned on or not.
 *
 * @see template_preprocess_admin_block_content()
 * @see seven_preprocess_admin_block_content()
 * @see myadmintheme_preprocess_admin_block_content()
 */
#}
{%
  set classes = [
    'admin-list',
    compact ? 'compact',
  ]
%}
{% if content %}
  &lt;ul{{ attributes.addClass(classes) }}&gt;
    {% for item in content %}
      &lt;li&gt;&lt;a href="{{ item.url }}"{{ item.attributes }}&gt;&lt;span class="label"&gt;{{ item.title }}&lt;/span&gt;&lt;div class="description"&gt;{{ item.description }}&lt;/div&gt;&lt;/a&gt;&lt;/li&gt;
    {% endfor %}
  &lt;/ul&gt;
{% endif %}



In the example code here the theme My Admin Theme (/themes/myadmintheme) is a child theme of Drupal's default admin theme Seven.