- $tree = CRM_Core_BAO_CustomGroup::getTree($ctype, NULL, NULL, -1);
+
+ $subTypes = $fields['contact_sub_type'] ?? [];
+ // Only return custom for subType + unrestricted or return all custom
+ // fields.
+ $tree = CRM_Core_BAO_CustomGroup::getTree($ctype, NULL, NULL, -1, $subTypes, NULL, TRUE, NULL, TRUE);