FAL relation + flexform config: Use full setting path as name
Multiple FAL relations in a single flexform do not work if the fields have the same name, but different path (through nesting).
@NamelessCoder described the problem as follows:
The situation is that the FAL relation field types were initially created for purely record relations, and the support for using the same field in a FlexForm context is more of an afterthought; an adaptation that allows the field to store at least basic relations when used in a FlexForm.
Technically, the issue is that when you save a record that has a FlexForm with a FAL field, the FAL relation is stored using the field name without considering the nesting which means that all your relations have the field name image after they're saved. Of course, when you reload the form, the methods that pre-fill the FAL relation fields are then detecting the same relation in all fields.
The solution would be to parse the nesting structure of the FlexForm when determining which field name to use when the relation is stored in the database. This would allow TYPO3 to store a field name like settings.foreground.image in your case, rather than simply image. If the method that renders the field is then also capable of determining the same (I believe this needs to be added) the puzzle should be solved, allowing any combination of nested FAL/IRRE fields inside and outside FlexForms in the same way.