/**
* Binds given data to the subform and its elements.
*
* @param Form $subForm Form instance of the subform.
*
* @return Form[] Array of Form instances for the rows.
*
* @since 3.9.7
*/
protected function loadSubFormData(Form $subForm)
{
$value = $this->value ? (array) $this->value : array();
// Simple form, just bind the data and return one row.
if (!$this->multiple) {
$subForm->bind($value);
return array($subForm);
}
// Multiple rows possible: Construct array and bind values to their respective forms.
$forms = array();
$value = array_values($value);
// Show as many rows as we have values, but at least min and at most max.
$c = max($this->min, min(\count($value), $this->max));
for ($i = 0; $i < $c; $i++) {
$control = $this->name . '[' . $this->fieldname . $i . ']';
$itemForm = Form::getInstance($subForm->getName() . $i, $this->formsource, array('control' => $control));
if (!empty($value[$i])) {
$itemForm->bind($value[$i]);
}
$forms[] = $itemForm;
}
return $forms;
}