/**
* @throws \RuntimeException
* @param \Symfony\Component\Form\FormBuilder $formBuider
* @param $elementId
* @return \Symfony\Component\Form\FormBuilder
*/
public function getChildFormBuilder(FormBuilder $formBuider, $elementId)
{
// todo : warning this introduce a bug if the field name = 'field_name',
// add a check to field will always be 'fieldName'
$elements = explode('_', $elementId);
// always remove the first element : form's name
array_shift($elements);
while ($elementName = array_shift($elements)) {
if (!$formBuider->has($elementName)) {
throw new \RuntimeException(sprintf('The element `%s` does not exists', $elementName));
}
$formBuider = $formBuider->get($elementName);
}
return $formBuider;
}