Skip to content

Commit b2c6bc0

Browse files
authored
Add OptionsResolver note
1 parent 1c98673 commit b2c6bc0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/TwigComponent/doc/index.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,20 @@ component use a ``PreMount`` hook::
481481
// ...
482482
}
483483

484+
.. note::
485+
486+
In its default configuration, the OptionsResolver treats all props.
487+
However, if more props are passed than the options defined in the OptionsResolver, an error will be prompted, indicating that one or more options are not defined.
488+
To avoid this, it is necessary to use the `ignoreUndefined()` method with `true`. See `ignore not defined options`_ for more info.
489+
490+
$resolver->setIgnoreUndefined(true);
491+
492+
The major drawback of this configuration is that the OptionsResolver will remove every non-defined option when resolving data.
493+
In order to maintain the props that have not been defined within the option resolver, it is necessary to combine the data from the hook with the result of the resolved data.
494+
495+
return $resolver->resolve($data) + $data;
496+
497+
484498
The data returned from ``preMount()`` will be used as the props for mounting.
485499

486500
.. note::
@@ -1656,3 +1670,4 @@ https://symfony.com/doc/current/contributing/code/bc.html
16561670
.. _`CVA (Class Variant Authority)`: https://cva.style/docs/getting-started/variants
16571671
.. _`shadcn/ui`: https://ui.shadcn.com
16581672
.. _`tales-from-a-dev/twig-tailwind-extra`: https://github.com/tales-from-a-dev/twig-tailwind-extra
1673+
.. _`ignore not defined options`: https://symfony.com/doc/current/components/options_resolver.html#ignore-not-defined-options

0 commit comments

Comments
 (0)