We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Running this code doesn't prefill the group fields:
class PersonGroupType extends AbstractGroupType { public function build(): void { $this->add('first_name', TextType::class); $this->add('last_name', TextType::class); } } $data = [ 'people' => [ ['first_name' => 'Peter', 'last_name' => 'Parker'] ] ]; $builder = new FormBuilder([ 'key' => 'collection_example', 'method' => 'POST', 'html_validation' => false, ], $data); $builder->add('people', CollectionType::class, ['entry_type' => PersonGroupType::class]); $builder->add('send_message', 'submit'); $form = $builder->getForm();
The method CollectionType::buildEntry could pass the data to the children:
CollectionType::buildEntry
private function buildEntry(int $position = 0, $data = null): TypeInterface { $entryType = $this->entryType; /** @var TypeInterface $entry */ $entry = new $entryType($this->entryOptions); $entry ->setParent($this) ->setName($this->name) ->setPosition($position) ; if ($entry->getLabel() === null) { $entry->setLabel($this->getHumanName()); } $entry->build(); if (\func_num_args() > 0) { $entry->setData($data); //NEW if(is_array($data)) { foreach ($entry->all() as $child) { if(isset($data[$child->getName()])) $child->setData($data[$child->getName()]); } } } return $entry; }
The text was updated successfully, but these errors were encountered:
Hey there,
Thanks for reporting this and providing a fix!
I've created a PR for this: #14 - could you test it and see if it resolves the issue for you?
If you want to install the PR branch via composer you can run the following command:
composer require palmtree/form:dev-13-support-data-binding-for-collectiontype
Sorry, something went wrong.
andyexeter
Successfully merging a pull request may close this issue.
Running this code doesn't prefill the group fields:
The method
CollectionType::buildEntry
could pass the data to the children:The text was updated successfully, but these errors were encountered: