symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
782 stars 273 forks source link

[TwigComponent] Autodiscover from bundles #1714

Open cavasinf opened 2 months ago

cavasinf commented 2 months ago

The goal is to convert every "twig macro component" into TwigComponent (https://github.com/kevinpapst/TablerBundle/issues/173) in TablerBundle.

As of today, there is no "best practice" or "how to" for implementing TwigComponent in bundles. With the multi namespace available, we can configure it like this:

twig_component:
    defaults:
        KevinPapst\TablerBundle\Twig\Components\:
            template_directory: '@Tabler/twig_components/'
            name_prefix: Tabler

[!NOTE] Keep in mind the /twig_components folder.

  1. Will an auto-discovery be available later like Bundle Templates to auto map Bundle TwigComponents?
  2. Should each twig file in <your-bundle>/templates/components be mounted as a Twig Component? In our case, we already have a components folder that is NOT planned for Twig Component (this can be solved internally).
  3. Depending on the answer to 2., can a bundle have "anonymous" components?
  4. Should the DI only inject php classes that have the Symfony\UX\TwigComponent\Attribute\AsTwigComponent attribute and not mount them from "is there twig files in templates/components"
  5. Can a TwigComponent be overrided like Bundle templates
smnandre commented 2 months ago

Concerning autodiscover / bundle component, i'll make you a general answer :)

It's somehting we worked on and.. paused (to release some LiveComponent fixes and UX Icons).

I'll work on it next week as i had an almost ready PR for all this, we "just" need to act some things regarding namespaces.

Stay tuned ? :)

cavasinf commented 2 months ago

Stay tuned ? :)

I'll ping you next week then 😉

kevinpapst commented 2 months ago

Let me be the ping on that one. Can we help with a real world example? Do you have a working branch that we can help testing @smnandre ?

smnandre commented 2 months ago

Nothing like that nope sorry…. But if you want, i can find 30mn during the week-end to centralize all the needs / hidden problems / things we want to préserve, etc