function civicrm_entity_contact_assign_rel_contact_field_field_widget_form in CiviCRM Entity 7.2
Implements hook_field_widget_form().
File
- modules/
civicrm_entity_contact_assign_rel_contact_field/ civicrm_entity_contact_assign_rel_contact_field.module, line 380 - Provide CiviCRM Entity Contact Assign Relationship Contacts List Field Type. Provides a widget for adding/removing a contacts relationships to a list of contacts.
Code
function civicrm_entity_contact_assign_rel_contact_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$orig_element = $element;
$options = _civicrm_entity_contact_assign_rel_contact_field_get_field_settings_contacts($field);
$values = array();
if (!empty($items[$delta]['contacts'])) {
foreach ($items[$delta]['contacts'] as $contact_b_id => $value) {
$values[$contact_b_id] = $value;
}
}
switch ($instance['widget']['type']) {
case 'civicrm_entity_contact_assign_rel_contact_field_checkboxes_widget':
$widget = array();
$widget = $orig_element + array(
'#type' => 'checkboxes',
'#default_value' => $values,
'#options' => $options,
);
$widget['#title'] = $instance['label'];
$widget['#weight'] = 0;
$element['contacts'] = $widget;
break;
case 'civicrm_entity_contact_assign_rel_contact_field_radios_widget':
$default_value = 0;
foreach ($values as $contact_id => $value) {
if ($value) {
$default_value = $contact_id;
break;
}
}
$widget = array();
$widget = $orig_element + array(
'#type' => 'radios',
'#default_value' => $default_value,
'#options' => $options,
);
$widget['#title'] = $instance['label'];
$widget['#weight'] = 0;
$element['contacts'] = $widget;
break;
}
return $element;
}