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

Add failing test case for factory creation of elements with required options #283

Open
wants to merge 1 commit into
base: 3.22.x
Choose a base branch
from

Conversation

gsteel
Copy link
Member

@gsteel gsteel commented Feb 5, 2025

It is not possible to use custom elements with required options via configuration, i.e.

$this->add([
  'name' => 'foo',
  'type' => Whatever::class,
  'options' => ['some' => 'thing'],
]);

This can be fixed in Factory by passing any options found in $spec but this reveals more problematic issues with collections, for example. Because the options are given to the Collection at construction time, it creates the nested element(s) before the factory has been injected (via setter injection in the plugin manager initialisers) - This causes a fresh plugin manager to be created inside the collection with a call to ->get('NestedElement') for an unknown element (By default the plugin manager will auto add an invokable factory).

…options.

This can be fixed in [Factory](https://github.com/laminas/laminas-form/blob/3.22.x/src/Factory.php#L110) by passing any options found in `$spec` but this reveals more problematic issues with collections, for example. Because the options are given to the Collection at construction time, it creates the nested element(s) before the factory has been injected (via setter injection in the plugin manager initialisers) - This causes a fresh plugin manager to be created inside the collection with a call to `->get('NestedElement')` for an unknown element (By default the plugin manager will auto add an invokable factory).

Signed-off-by: George Steel <[email protected]>
@gsteel gsteel added the Bug Something isn't working label Feb 5, 2025
@gsteel gsteel requested a review from Slamdunk February 5, 2025 23:45
@gsteel
Copy link
Member Author

gsteel commented Feb 5, 2025

Probaly related to #251 and #3

@Slamdunk
Copy link
Contributor

Slamdunk commented Feb 6, 2025

I got to be honest I forgot how any of this works: the FormElementManager has always been so clumsy and cumbersome that I move to $form->add(new MyElement); everywhere long time ago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants