Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tacman opened this issue Nov 11, 2024 · 3 comments
Open

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

tacman opened this issue Nov 11, 2024 · 3 comments

Comments

@tacman
Copy link
Contributor

tacman commented Nov 11, 2024

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 tacman added the RFC label Nov 11, 2024
@smnandre
Copy link
Member

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.

@tacman
Copy link
Contributor Author

tacman commented Nov 12, 2024

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?

@smnandre
Copy link
Member

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants