Changing entity for custom field group breaks associations with fields used in profiles
Not a serious issue, but if you change the 'entity' which a custom field group uses, it breaks the association between fields in that group, and where those fields are exposed in profiles. The fields do continue to work in profiles, but can break when edited.
Steps to recreate on dmaster:
- Create a new custom field group used for 'contact' entity 'Group to change'
- Add a text field 'Field to change'
- Create a profile 'Profile 1', add 'Field to change' to it, save
- Edit the field group settings on 'Group to change'
- Change used for 'Contacts' to 'Individual' > 'Any'
- Go to 'Profile 1', edit 'Fields'
- Notice that 'Field to change' still says '(Contact)'
- Click to 'Edit' it, it shows the first alphabetical 'Contact' field instead, which is 'Address Name'
- If you save changes to the field, witout re-selecting the correct field, the field will be replaced
When the entity a field group extends is updated, update references to it in the civicrm_uf_field table as well.
(Or, maybe better, don't store the field_type in the civicrm_uf_field table at all, because otherwise we're duplicating data! But that's a bigger fix with more implications...)
Query to highlight fields which have inconsistent types in the group and profile field table:
SELECT * FROM civicrm_custom_group cg left join civicrm_custom_field cf on cf.custom_group_id = cg.id left join civicrm_uf_field uf on uf.field_name = CONCAT('custom_', cf.id) where uf.field_type is not null and cg.extends <> uf.field_type;