- Issue created by @reszli
- Status changed to Needs review
over 1 year ago 11:06am 29 March 2023
I tried to add some extra classes to the node edit local task in a preprocess hook, but it was not rendered.
Switching to default Olivero theme rendered it properly.
Figured the twig template was not preserving the classes.
/**
* Implements hook_preprocess_menu_local_task().
*/
function MYMODULE_preprocess_menu_local_task(&$variables) {
/** @var \Drupal\Core\Url $url */
$url = $variables['link']['#url'];
if ($url instanceof Url && $url->getRouteName() === 'entity.node.edit_form') {
$variables['link']['#options']['attributes']['class'][] = 'content-wizard-enabled';
}
}
Preserve existing classes in the twig template.
diff --git a/templates/BASE/components/00-theme/01-atoms/09-menu/tab/_tab.twig b/templates/BASE/components/00-theme/01-atoms/09-menu/tab/_tab.twig
index f4946b5..24c8af9 100755
--- a/templates/BASE/components/00-theme/01-atoms/09-menu/tab/_tab.twig
+++ b/templates/BASE/components/00-theme/01-atoms/09-menu/tab/_tab.twig
@@ -21,6 +21,9 @@
'tabs__link--local-tasks'
]
%}
+{% if link['#options']['attributes']['class'] is defined %}
+ {% set link_classes = link_classes|merge(link['#options']['attributes']['class']) %}
+{% endif %}
{# if Pattern Lab atoms example, add ul wrapper #}
{% if example %}
Create a fork / patch.
Needs review
3.8
Code