function _civicrm_entity_contact_assign_rel_type_list_field_process_field_items in CiviCRM Entity 7.2
Helper function to process field items on entity insert or update
Parameters
$contact_a_id:
$field:
$items:
2 calls to _civicrm_entity_contact_assign_rel_type_list_field_process_field_items()
- civicrm_entity_contact_assign_rel_type_list_field_field_insert in modules/
civicrm_entity_contact_assign_rel_type_list_field/ civicrm_entity_contact_assign_rel_type_list_field.module - Implements hook_field_insert().
- civicrm_entity_contact_assign_rel_type_list_field_field_update in modules/
civicrm_entity_contact_assign_rel_type_list_field/ civicrm_entity_contact_assign_rel_type_list_field.module - Implements hook_field_update().
File
- modules/
civicrm_entity_contact_assign_rel_type_list_field/ civicrm_entity_contact_assign_rel_type_list_field.module, line 447 - Provide CiviCRM Entity Contact Assign Relationship Type List Field Type. Provides a widget for adding/removing a contacts relationships to a configured global contact.
Code
function _civicrm_entity_contact_assign_rel_type_list_field_process_field_items($contact_a_id, $field, &$items) {
$field_settings_relationship_types = array_keys(_civicrm_entity_contact_assign_rel_type_list_field_get_field_settings_relationship_types($field));
$contact_b_id = $field['settings']['target_contact_b'];
if (!is_array($items[0]['relationship_types'])) {
$set_value = $items[0]['relationship_types'];
$items[0]['relationship_types'] = array();
foreach ($field_settings_relationship_types as $relationship_type_id) {
if ($relationship_type_id == $set_value) {
$items[0]['relationship_types'][$relationship_type_id] = $set_value;
}
else {
$items[0]['relationship_types'][$relationship_type_id] = 0;
}
}
}
foreach ($items[0]['relationship_types'] as $relationship_type_id => $value) {
// ignore any programmatically added relationship_type id keys that aren't in the field settings list
if (in_array($relationship_type_id, $field_settings_relationship_types)) {
// if group id has a non-zero, check to see if contact has relationship, and if not, create it
if ($value) {
if (!_civicrm_entity_contact_assign_rel_type_list_field_contact_has_relationship($contact_a_id, $contact_b_id, $relationship_type_id)) {
_civicrm_entity_contact_assign_rel_type_list_field_add_contact_relationship($contact_a_id, $contact_b_id, $relationship_type_id);
}
}
else {
if (_civicrm_entity_contact_assign_rel_type_list_field_contact_has_relationship($contact_a_id, $contact_b_id, $relationship_type_id)) {
_civicrm_entity_contact_assign_rel_type_list_field_remove_contact_relationship($contact_a_id, $contact_b_id, $relationship_type_id);
}
}
}
}
}