-
-
Notifications
You must be signed in to change notification settings - Fork 341
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
Adding convention to load Anonymous components from bundles #2019
Conversation
1dd5a5f
to
d274972
Compare
Thanks @yceruto! Am I correct in that there are now two ways to override bundle component templates:
This does make me a little hesitant but what does everyone else think? I think, when we document, we only show (2) as the proper way to override a bundle's template as it's familiar. |
You are correct Kevin! This adds another way to override the bundle components, with the possibility to extend from the original one with I agree with you that we should not document it and keep the standard one for consistency. |
We could change the priority to avoid that, but I’m afraid it might break some apps already using a directory that matches a bundle namespace + template path. |
First thing first: thank you @yceruto 🙇 -- Concerning the "extends", we need to tests a lot of differents scenario, because we use the "logical name" during embedding i think and not the full path. So i'm not entirely sure "bundles/AcmeBundle/components/Button.html.twig" and "@Acme/components/Button.html.twig" are considered the same template. Also, i'm not sure parent() will refer to the bundle original template ... because of the fake one we inject. -- Currently, symfony use "Collector" or "Form" as directory names... should we use "Component" instead of "components" in the bundle structure ? Singular / plural ? Once we will open this it will be very very hard to change :) -- Security point I also think we need some BC break from now, because we allow any string as bundle name, and this can pose security risks (at least weird DX).. Not sure which but i remember at least one of these is problematic <twig:Foo:: />
<twig:..Foo:: />
<twig:../Foo:: /> I suggest we allow only something that looks like a class name (the check may be done earlier in the renderer) If that's ok for you, i'll open another PR to discuss this and not pollute this one :) -- After everything, thank you @yceruto ;) |
As long as the template loading is done using the Twig template naming convention, everything should work. Once
I've no strong opinion about it. Personally, I prefer a lowercase directory structure, even for bundles, but it's up to you. I used the plural form for consistency with the
The security point is important, but I believe we should address that discussion in a separate PR. |
Thanks @yceruto for this great PR! This is a solution I really believe in, but to give some more context 6 months ago I made a similar proposal and it was refused for several reasons: The bundle doesn't have controls over the components imported or not on the user side (everything is imported by default), and this may be something that the maintainer of the bundle doesn't want. Should we think about a way to exclude some components or not? This is why I ended up with this proposal a few months ago: #1456. Should we still be concerned about this ? |
The discussion is the foundation of today's work! We agreed on the requirements and acted the "specs" @yceruto filled in this PR :)
For class-based components, i would totally understand. Would you have an example scenario ? |
Thanks @WebMamba for your input!
This is the case for all bundle templates, not just the component ones. Once they're in the templates directory, they become public. Even if some templates are not meant to be extended or used in applications, it's the user's decision and risk. I don't think we can/should prevent that. |
For me, this is completely fine! Everything is good for me! |
Yep, I totally agree, the opt-in occurs when an app uses the anon component. @yceruto could you add the docs? I'm thinking a new 3rd Party Bundle section and a sub-section for anon components. We'll add to it once we figure out how to best provide class-based components. BTW, I think this opt-in strategy works just the same for class-based twig components. For live components, I was concerned about the security concern (someone being able to access the http endpoint for a component that isn't used) but I don't think that'll be an issue either. I forgot about the checksum, unless the end app actually renders a live component in twig, the checksum won't be valid. We'll need to confirm this of course. |
We just forced a hardcoded namespace, we need to find something similar to register class-based This probably means not use the tag i guess ? |
Regarding Live component I think checking before would be nice indeed... I am not entirely sure checksum is used for actions for instance (with no changes). |
Here also the tag must probably be ignore (at least partially) to prevent route or URL override |
Only the doc is left to complete, but I'm having trouble finishing it before next weekend. Feel free to take over if you want to move forward |
d274972
to
4ab0400
Compare
Update:
This is ready for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for this PR @yceruto
4ab0400
to
c207af6
Compare
Thanks again for this first step to better 3rd party bundle support Yonel! |
Thank you so much @yceruto ! |
Sorry, i dont know if this is the correct place to post this, (will be glad to open a new issue if this isnt)
Just a heads up, if there is a subfolder inside /templates/components, it breaks the TwigComponentDebugCommand
Even though, twig correctly renders the component using the :Folder:ComponentName described in the original post. |
Thanks @rrenteria-dev, I've created an issue. |
This adds a fallback convention to check if a requested anonymous component,
<twig:Acme:Alert>
, exists on the bundle side using the current Twig loading convention.The resolution process would work like this:
components/Acme/Alert.html.twig
exists (resolving to<app>/templates/components/Acme/Alert.html.twig
)@Acme/components/Alert.html.twig
exists (resolving to<bundle>/templates/components/Alert.html.twig
) (this is the new code)Here, the
components
directory is hardcoded for bundles, asanonymous_template_directory
is exclusively a userland configuration.From here, you can organize your components into subdirectories if desired. For example, a component like
<twig:Acme:Table:Header>
will be located in<acme-bundle>/templates/components/Table/Header.html.twig
.TODO: