public function RelationsImportSettingsBase::formAttachFieldRelation in CRM Core 7
Attach one relation field to form.
1 call to RelationsImportSettingsBase::formAttachFieldRelation()
- RelationsImportSettingsBase::formAttachRelations in modules/
crm_core_data_import/ plugins/ settings/ RelationsImportSettingsBase.inc - Attach relation fields to form.
File
- modules/
crm_core_data_import/ plugins/ settings/ RelationsImportSettingsBase.inc, line 112 - Base relations settings handler for CRM Core Data Import.
Class
- RelationsImportSettingsBase
- @file Base relations settings handler for CRM Core Data Import.
Code
public function formAttachFieldRelation(&$form, &$form_state, $settings, $source, $destination, $relation_type_object, $delta) {
$source_values = array();
$destination_values = array();
foreach ($source as $relation) {
$list = $this
->getMatchMappingEntity('crm_core_contact', $relation->type, $settings);
foreach ($list as $key => $item) {
$source_values[$key] = crm_core_data_import_get_destination_label($item['entity_controller_type'], $item['entity_bundle'], $item['delta']);
}
}
foreach ($destination as $relation) {
$list = $this
->getMatchMappingEntity('crm_core_contact', $relation->type, $settings);
foreach ($list as $key => $item) {
$destination_values[$key] = crm_core_data_import_get_destination_label($item['entity_controller_type'], $item['entity_bundle'], $item['delta']);
}
}
$form['relations']['fields'][$delta] = array(
'#type' => 'fieldset',
'#attributes' => array(
'class' => array(
'settings-fieldset',
),
),
);
$form['relations']['fields'][$delta]['source'] = array(
'#type' => 'select',
'#options' => $source_values,
'#default_value' => !empty($form_state['values']['relations']['fields'][$delta]['source']) ? $form_state['values']['relations']['fields'][$delta]['source'] : FALSE,
);
$form['relations']['fields'][$delta]['label'] = array(
'#type' => 'item',
'#markup' => $relation_type_object->label,
);
$form['relations']['fields'][$delta]['destination'] = array(
'#type' => 'select',
'#options' => $destination_values,
'#default_value' => !empty($form_state['values']['relations']['fields'][$delta]['destination']) ? $form_state['values']['relations']['fields'][$delta]['destination'] : FALSE,
);
$form['relations']['fields'][$delta]['relation_type'] = array(
'#type' => 'value',
'#value' => $relation_type_object->relation_type,
);
$form['relations']['fields'][$delta]['remove_field'] = array(
'#type' => 'button',
'#value' => t('Remove'),
'#name' => drupal_html_id('relations-settings-remove-button-' . $delta),
'#ajax' => array(
'callback' => '_crm_core_data_import_relations_callback',
'method' => 'replace',
'wrapper' => 'relations-form-fields-wrapper',
),
);
}