ux icon indicating copy to clipboard operation
ux copied to clipboard

[icons] Dispatch an event during ux:icons:lock

Open tacman opened this issue 1 year ago • 7 comments

I'm using knp_dictionary to define icons by class:

    $containerConfigurator->extension('knp_dictionary', [
        'dictionaries' => [
            'class_icons' => [
                'type' => 'key_value',
                'content' => [
                    \App\Entity\Member::class => 'mdi:user',
                    \App\Entity\DirectoryCollection::class => 'mdi:users',
                    \App\Entity\Tag::class => 'mdi:tag',
                    \App\Entity\Donation::class => 'mdi:dollar',
                    \App\Entity\CommunicationLog::class => 'mdi:envelope',
                    \App\Entity\Event::class => 'tabler:calendar'
                ]
            ],

These work as expected in dev, as the ux_icon renderer fetches the icon on demand. I'd like to import them to production during the lock

bin/console ux:icons:lock

Of course, it doesn't now. My idea for implementation is dispatching an event that I could listen for and add the icons based on how I store them. For example, I recently discovered https://github.com/zenstruck/class-metadata and considered putting my icons there instead, e.g.

#[Metadata('icon', 'mdi:user')]
class User

In one project I have the icons as twig globals in twig.yaml.

In short, I'd like a way to register variable icons to make the discoverable during the lock command.

tacman avatar Nov 11 '24 11:11 tacman

If you already have a way to list all of your icons, right now the best method would be to import them just before the lock with some PhpSubProccess?

I've updated its code the other day and it now downloads up to 60 icons at once (if they have common iconset), this should be very quick.

smnandre avatar Nov 12 '24 00:11 smnandre

the best method would be to import them just before the lock with some PhpSubProccess?

I'm not following. I have my icons sprinkled about, in twig, in yaml, in php, in attributes, and maybe someday in the database.

They work in dev, but not in prod (because of the very slick fetching). I'm not familiar with PhpSubProccesses.

Obviously, I could copy the lock command and tweak it for my purposes. But it seems ripe for extending, right now it's pretty much a regex in the twig file. Which pretty much finds anything with a colon in a string:

ux:icons:lock -vvv

 // Scanning project for icons...                                                                                       

 ✗ IconSet Not Found: max-height:40vh.
 ✗ IconSet Not Found: max-height:70vh.
 ✗ IconSet Not Found: max-width:40rem.
 ✗ IconSet Not Found: max-height:30vh.
 ✗ IconSet Not Found: color:transparent.
 ✗ IconSet Not Found: lg:col-6.
 ✗ IconSet Not Found: width:30px.

Can you point me to what you mean by a PhpSubProccess?

tacman avatar Nov 12 '24 00:11 tacman

Of course! Here is the documentation related to your need: Executing a PHP Child Process with the Same Configuration

Let's say your icons are a:foo, b:bar and b:foobar

$childProcess = new PhpSubprocess(['bin/console', 'ux:icons:import', ['a:foo', 'b:bar', 'b:foobar']);
$childProcess->run();

This will run the import command in the same configuration / environment that your code is, and will allow you to use the UX Icons import command !

Finally, if you have a fixed list of icons, the best method is probably to commit them in the repository :)

smnandre avatar Nov 12 '24 02:11 smnandre

Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature? Every feature is developed by the community. Perhaps someone would like to try? You can read how to contribute to get started.

carsonbot avatar May 13 '25 12:05 carsonbot

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

carsonbot avatar May 27 '25 12:05 carsonbot

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

carsonbot avatar Jun 10 '25 12:06 carsonbot

Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature? Every feature is developed by the community. Perhaps someone would like to try? You can read how to contribute to get started.

carsonbot avatar Dec 11 '25 12:12 carsonbot