function crm_core_contact_join_into_household_action in CRM Core 7
Creates household with specified members.
File
- modules/
crm_core_contact/ crm_core_contact.module, line 1058 - Provides default CRM Core Contact entities and the ability to create more.
Code
function crm_core_contact_join_into_household_action($selected_contacts, $context) {
$household = $context['household'];
// Saving household only now because user can click "Cancel" on confirmation
// page(if he/she will notice that selected wrong contacts).
$household->uid = $GLOBALS['user']->uid;
crm_core_contact_save($household);
$relation_type = 'crm_member';
foreach ($selected_contacts as $member) {
if ($member->type == 'individual') {
$endpoints = array(
0 => array(
'entity_type' => 'crm_core_contact',
'entity_id' => $member->contact_id,
),
1 => array(
'entity_type' => 'crm_core_contact',
'entity_id' => $household->contact_id,
),
);
$relation = relation_create($relation_type, $endpoints);
relation_save($relation);
}
}
}