Add a form to choose which icon (for a first time among drupal core icons) to display for each toolbar menu element + each tray element

Comments

vpeltot created an issue. See original summary.

juliencarnot’s picture

Wouldn't changing the default cog.svg to the more generic hamburger.svg and documenting the classes generated by the modules and the toolbar_menu/css/toolbar_menu.module.css (which could include the default hover variations to it) be easier and simpler?

farald’s picture

Hm, can we have it react to classes defined as fields on the menu link entry?

I made a quick approach, since I only needed minor changes to existing logic.
Since ToolbarMenuMenuLinkTreeManipulators is a service, I swapped it out with:

<?php

namespace Drupal\mymodule;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;

/**
* Allows us to add our own
*/
class MymoduleServiceProvider extends ServiceProviderBase {

  /**
  * {@inheritdoc}
  */
  public function alter(ContainerBuilder $container) {
  $definition = $container->getDefinition('toolbar_menu.menu_link_tree_manipulators');
  $definition->setClass('Drupal\mymodule\ToolbarMenuTreeManipulators');
  }
}

And then using the ToolbarMenuMenuLinkTreeManipulators as base class.

dbiscalchin’s picture

Status: Active » Needs review
StatusFileSize
new11.21 KB

Hi,

This is a patch I made to allow configuring the icons used in the toolbar. It was created from the Git version of the code.

The file css/toolbar_menu.module.css could be deleted, but I did not in case someone else is using the library declared by the module.

Regards,

dbiscalchin’s picture

StatusFileSize
new21.78 KB

I've attached a screenshot of the configuration page.

It would be nice to upload images. However, I think it should be easily used programmatically too.

dunebl’s picture

I confirm #4 is doing the job...
Maybe the text under the icon path could leads to confusion:
Absolute URL path to the icon image. Leave it empty for no icon.
Regarding the Absolute URL path text: Maybe it should be like under the "logo" field (/admin/appearance/settings):
Enter a path to an icon. Drupal will look for the file relative to the Drupal root or the public file system.
With the exception that this path require a "/" at the beginning .

dunebl’s picture

#4 apply with few warning on last dev:

patching file config/schema/toolbar_menu_element.schema.yml
patching file src/Entity/ToolbarMenuElement.php
Hunk #1 succeeded at 117 (offset 7 lines).
patching file src/Form/ToolbarMenuElementEditForm.php
Hunk #4 succeeded at 124 with fuzz 2.
patching file src/ToolbarMenuCssGenerator.php
patching file templates/toolbar-menu-css-icons.html.twig
patching file toolbar_menu.install
Reversed (or previously applied) patch detected!  Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file toolbar_menu.install.rej
patching file toolbar_menu.module
patching file toolbar_menu.services.yml
sutharsan’s picture

Status: Needs review » Needs work

This is a very complex approach, I would rather have a symplistic solution using CSS classes as @falard suggested in #3.

mrpauldriver’s picture

I have used Font Awesome Menu Icons with some success.

dunebl’s picture

#4 doesn' work in 9.x as it is using deprecated function : file_prepare_directory

dunebl’s picture

StatusFileSize
new11.36 KB

Here is an updated patch

dunebl’s picture

Status: Needs work » Needs review
StatusFileSize
new7.08 KB

Some patch generation problem fixed.
Please review

Status: Needs review » Needs work

The last submitted patch, 12: toolbar_menu-Change_icons_for_toolbar_menu_entries-2664432-12-9.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dunebl’s picture

I really have a problerm with this patch... here is the correct version.
Sorry for the wrong patches.

dunebl’s picture

Status: Needs work » Needs review
crutch’s picture

#14 - patch applies but is not saving the entries (urls). After saving, the icon does not appear and then when going back to edit the item the fields are blank. No errors.

Attempted to use: /core/misc/icons/bebebe/cog.svg and https://localhost/web/core/misc/icons/bebebe/cog.svg

D9.3.3
toolbar_menu 2.x-dev + #14