Commit 2c48d1a2 authored by bgm's avatar bgm Committed by Aegir user
Browse files

Add support for setting the contact type/subtype even if not using activities

parent 0482777c
......@@ -189,4 +189,30 @@ function activityprofile_civicrm_post($op, $objectName, $objectId, &$objectRef)
}
}
}
// This is a bit redundant with the APIWrapper code for Profile submission
// but that code only kicks-in when using remoteform and Activity fields.
// This makes it possible to set the contact-type/subtype if using just a plain profile.
if ($objectName == 'Profile' && $op == 'create') {
$profile_id = $objectRef['uf_group_id'];
$ctype = Civi::settings()->get('activityprofile_' . $profile_id . '_ctype');
$csubtype = Civi::settings()->get('activityprofile_' . $profile_id . '_csubtype');
if ($ctype || $csubtype) {
$api = \Civi\Api4\Contact::update(false)
->addWhere('id', '=', $objectId);
if ($ctype) {
$api->addValue('contact_type', $ctype);
}
if ($csubtype) {
$api->addValue('contact_sub_type', [
$csubtype,
]);
}
$api->execute();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment