1

How can I print the admin toolbar icon for my module?

I created a module and it has a menu in the admin toolbar. I want to show an icon (module/costum_module/image/00/icon.svg) in this path for my admin toolbar tab.

I created a CSS style for that, but it doesn't work.

Module path :

/module/my module/css/styles.css =>

.toolbar-icon-mymodule-list:before {
    background-image: url(../icons/787878/icon.svg);
}
.toolbar-icon-mymodule-list:active:before,
.toolbar-icon-mymodule-list.active:before {
    background-image: url(../icons/000000/icon.svg);
}

/module/my module/mymodule.libraries.yml =>

mymodule.styles:
  css:
    theme:
      css/styles.css: {}
  • 3
    You did not tell what you've tried and why it is not working. You can use the css from the toolbar module as example: cgit.drupalcode.org/drupal/tree/core/modules/toolbar/css/… – 4k4 Feb 4 '17 at 16:33
  • 1
    I take that @4k4 also means you aren't showing the CSS styles you added, and you aren't telling us how you added them. – kiamlaluno Feb 4 '17 at 16:59
  • I edit my question . – RobinSon Feb 5 '17 at 5:11
  • Can you be more specific about what is not working? – 4k4 Feb 5 '17 at 10:56
1

If you want to add svg icon for your menu link item in admin toolbar, you have to alter toolbart.

In your mymodule.libraries.yml file

toolbar: version: VERSION css: theme: css/styles.css: {}

And you need to implement hook_toolbar_alter() in your mymodul.module

function mymodule_toolbar_alter(&$items) {
  $items['administration']['#attached']['library'][] = 'mymodule/toolbar';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.