Skip to content

Instantly share code, notes, and snippets.

@ABM-Dan
Last active February 22, 2016 17:07
Show Gist options
  • Save ABM-Dan/c3692a8e08094612f25f to your computer and use it in GitHub Desktop.
Save ABM-Dan/c3692a8e08094612f25f to your computer and use it in GitHub Desktop.
Embedded Form shenanigans
<?php
// in the controller
$user->addCreditCard(new CreditCard());
// this actually shows up in the form.
$user->getCreditCards()[0]->setCvv(123);
// in the outer form type
$builder->add(
'credit_card',
CollectionType::class,
[
'type' => CreditCardType::class,
'property_path' => 'creditCards',
'entry_options' => [
//'validation_groups' => ['credit_card'],
'container' => $container,
// this is just me being desperate
'constraints' => [new Assert\Valid(), new Assert\NotBlank()],
],
]
)
// Inner form type
// This is extra, just to test if the failure happens at entity level. But this check is ignored.
$builder->add('number', TextType::class, ['constraints' => [new Assert\NotBlank()]]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment