/** * Add a repeatable group of fields to the form. * * @param string $name Name of the repeatable group * @param RepeatableContainer $group The repeatable group */ protected function _addRepeatableGroup($name, RepeatableContainer $group) { $dynamic = new DynamicFormType(); // Add each field as a collection foreach ($group->getFields() as $field) { $dynamic->add($field->getName(), $field->getFormType(), $field->getFieldOptions()); } // Add the form to the main form $this->_builder->add($name, 'collection', ['label' => $group->getLabel(), 'type' => $dynamic, 'allow_add' => true, 'allow_delete' => true, 'data' => $this->_getDefaultValuesForRepeatableGroup($group)]); }