Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The theme_toolbar_toggle() function in core simply outputs a link, generated by the l() function. This link alone does not need to be run through the theme layer.
function theme_toolbar_toggle($variables) {
if ($variables['collapsed']) {
$toggle_text = t('Show shortcuts');
}
else {
$toggle_text = t('Hide shortcuts');
$variables['attributes']['class'][] = 'toggle-active';
}
return l($toggle_text, 'toolbar/toggle', array('query' => drupal_get_destination(), 'attributes' => array('title' => $toggle_text) + $variables['attributes']));
}
Let's move this link into the toolbar.html.twig file, and allow theme devs to change it there, if needed.
<nav id="toolbar" role="navigation" class="{{ attributes.class }} clearfix"{{ attributes }}>
<div class="toolbar-menu clearfix">
{{ toolbar.toolbar_home }}
{{ toolbar.toolbar_user }}
{{ toolbar.toolbar_menu }}
{% if toolbar.toolbar_drawer %}
{% if toolbar.collapsed %}
<a href="{{ url('toolbar/toggle', toolbar.options) }}"{{ toolbar.attributes }}>{{ 'Show shortcuts'|t }}</a>
{% elseif %}
<a href="{{ url('toolbar/toggle', toolbar.options) }}" class="toggle-active {{ toolbar.attributes.class }}"{{ toolbar.attribtues }}>{{ 'Hide shortcuts'|t }}</a>
{% endif %}
{% endif %}
</div>
{{ toolbar.toolbar_drawer }}
</nav>
Comments
Comment #0.0
jenlamptonadd twig example
Comment #1
jessebeach CreditAttribution: jessebeach commentedHi all, I just wanted to mention that the toolbar theme issues are being addressed in the responsive toolbar patch. I just switched from tpl to twig in the latest patch.
#1137920-282: Fix toolbar on small screen sizes and redesign toolbar for desktop
I would suggest closing this issue as a duplicate or at least postponing it. I'd like to avoid you all spending time on unnecessary work here.
Comment #2
thedavidmeister CreditAttribution: thedavidmeister commentedthe function theme_toolbar_toggle() does not exist in latest 8.x HEAD. This issue must be a duplicate, probably with the one referenced in #1.
Comment #2.0
thedavidmeister CreditAttribution: thedavidmeister commentedremove does