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(&$variables) {
if (!empty($variables['content'])) {
foreach ($variables['content'] as $key => $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 %}
<ul{{ attributes.addClass(classes) }}>
{% for item in content %}
<li><a href="{{ item.url }}"{{ item.attributes }}><span class="label">{{ item.title }}</span><div class="description">{{ item.description }}</div></a></li>
{% endfor %}
</ul>
{% endif %}
In the example code here the theme My Admin Theme (/themes/myadmintheme) is a child theme of Drupal's default admin theme Seven.