I have a subform field with multiple and a filelist field inside. Since I want to have the directory of the filelist field configurable, I have to modify the subform XML during runtime. There currently is no way to modify that. The only thing that worked was:
$field = $form->getField('attachments');
$subform = new \SimpleXmlElement($field->formsource);
$files = $subform->xpath('field[@name="file"]');
$files[0]->addAttribute('directory', JPATH_ROOT . '/' . $params->get('attachment_folder'));
$form->load('<form><field name="attachments" type="subform" '
. 'label="COM_MAILS_FIELD_ATTACHMENTS_LABEL" multiple="true" '
. 'layout="joomla.form.field.subform.repeatable-table">'
. str_replace('<?xml version="1.0"?>', '', $subform->asXML())
. '</field></form>');
We should have some way to modify that in a more sane way.