I need help with "sonata_type_collection" : Is there any way to define a default value (here : instance of existing entity) for a "sonata_type_collection" specific field? Or maybe a way to give him parameters?
Let me clarify this : Here is a screenshot of my actual "sonata_type_collection" form once rendered :
Is there any way to make the "Machine" field hold the current instance of the "MachineInfo" entity I am editing instead of the "No selection" text when you click the (very last) "Add" button ?
Here's my current 'configureFormFields" from "MachineInfoAdmin" :
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array('label' => 'Nom'))
->add('description', 'text', array('label' => 'Description'))
->add('internalReference', 'text', array('label' => 'Référence interne'))
;
//Already instantiated
if ($this->id($this->getSubject())) {
$formMapper
->add(
'machineParts',
'sonata_type_collection',
array(
'label' => "Pièces",
),
array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
)
)
;
}
}
I'm really stuck into that one, I hope that a savior can provide me his knowledge to help me m(_ _)m
I found the solution, and it was quite simple, i'm ashamed =__=" I forgot to set a reference to the MachineInfo in the newly instantiated MachinePart
public function addMachinePart(MachinePartsInfo $machineParts) {
$machineParts->setMachineInfo($this); //Missed this line
$this->machineParts[] = $machineParts;
return $this;
}
I hope this can help someone in the future :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With