[TwigComponent] Add provide() and inject() Twig functions#3512
[TwigComponent] Add provide() and inject() Twig functions#3512Kocal wants to merge 1 commit intosymfony:3.xfrom
provide() and inject() Twig functions#3512Conversation
9111aac to
7196f67
Compare
|
I will try to review it as soon as I have time, if possible. |
7196f67 to
2b5ddae
Compare
2b5ddae to
3c173e4
Compare
| public function getProvided(string $key): mixed | ||
| { | ||
| if (!$this->hasProvided($key)) { | ||
| throw new \InvalidArgumentException(\sprintf('No provided context for key "%s" found.', $key)); |
There was a problem hiding this comment.
Is this exception reachable because getProvided() is always preceded by hasProvided()?
| - Namespace your keys (``'inputOtp.maxLength'``, ``'tabs.active'``) to avoid | ||
| collisions. | ||
| - Calling ``provide()`` outside a component template throws. | ||
|
|
There was a problem hiding this comment.
You don't mention the second argument of inject() in the documentation.
|
|
||
| This complements :ref:`outerScope <embedded-components-outerScope>`, which | ||
| only exposes the immediate parent's local context. | ||
|
|
There was a problem hiding this comment.
You don't mention the "overwrite" behavior, but it's well tested :D.
|
You had proposed two syntaxes (#2522 (comment)):
I had a preference for React's syntax :D. What made you lean more toward Vue.js syntax rather than React? I tested with this example:
<twig:Fieldset:Field disabled>
<twig:Fieldset:Label>Full name</twig:Fieldset:Label>
<twig:Input name="full_name" />
<twig:Fieldset:Description>If you have a tiger, we'd like to know about it.</twig:Fieldset:Description>
</twig:Fieldset:Field>This is interesting because the It works well, I get the The rendering of Twig functions on this page https://symfony.com/doc/current/reference/twig_reference.html is interesting. Perhaps the same could be done for |
|
Thanks for the reviews :)
For two main reasons:
|
Suggestion for #2522, with a behavior similar to Vue.js.
Some components from Toolkit kits could be improved with this feature (will do it in another PR)