public function RelationsCiviCrmImportSettings::configForm in CRM Core 7
Configuration form for settings plugin.
Overrides RelationsImportSettingsBase::configForm
File
- modules/
crm_core_data_import/ plugins/ settings/ RelationsCiviCrmImportSettings.inc, line 36
Class
Code
public function configForm(&$form, &$form_state, $importer, $label) {
$settings = $importer
->getSettings();
$source_settings = $importer
->getSourceSettings();
$available_relations = array(
'new' => t('New relation'),
) + $this
->getAvailableRelations($settings);
$form['relations'] = array(
'#type' => 'container',
'#weight' => -10,
);
$form['relations']['title'] = array(
'#type' => 'item',
'#title' => $label,
);
$form['relations']['enable'] = array(
'#type' => 'value',
'#value' => TRUE,
);
$form['relations']['civicrm'] = array(
'#type' => 'value',
'#value' => TRUE,
);
$form['relations']['relations_values'] = array(
'#type' => 'container',
'#weight' => -10,
);
if (!empty($source_settings['civicrm_types']['CivicrmRelationshipEntityType']['entity_types'])) {
foreach ($source_settings['civicrm_types']['CivicrmRelationshipEntityType']['entity_types'] as $civicrm_relation => $active) {
if ($active) {
$civicrm_relation = crm_core_data_import_civicrm_api('relationship_type', 'get', array(
'id' => $civicrm_relation,
));
$relation_type_default_value = '';
$relation = reset($civicrm_relation);
// Get relation type default value.
if (!empty($settings['relations']['relations_values'][$relation['id']]['relation_type']) && $this
->relationIsAlreadyCreated($settings['relations']['relations_values'][$relation['id']]['relation_type'], $available_relations)) {
$relation_type_default_value = $settings['relations']['relations_values'][$relation['id']]['relation_type'];
}
elseif (!empty($settings['relations']['relations_values'][$relation['id']]['relation_type']) && $this
->relationShouldBeCreated($settings['relations']['relations_values'][$relation['id']]['relation_type'], $available_relations, $settings['relations']['relations_values'][$relation['id']]['new_relation_name'])) {
$relation_type_default_value = 'new';
}
$form['relations']['relations_values'][$relation['id']] = array(
'#type' => 'fieldset',
'#title' => $relation['description'],
);
$form['relations']['relations_values'][$relation['id']]['civicrm_relation_id'] = array(
'#type' => 'value',
'#value' => $relation['id'],
);
$form['relations']['relations_values'][$relation['id']]['source_entity'] = array(
'#type' => 'value',
'#value' => $relation['contact_type_a'],
);
$form['relations']['relations_values'][$relation['id']]['source_entity_markup'] = array(
'#markup' => $relation['contact_type_a'],
);
$form['relations']['relations_values'][$relation['id']]['source_relation_markup'] = array(
'#markup' => $relation['name_a_b'],
);
$form['relations']['relations_values'][$relation['id']]['relation_type'] = array(
'#type' => 'select',
'#options' => $available_relations,
'#empty_option' => t('-- Do not import --'),
'#default_value' => $relation_type_default_value,
);
$form['relations']['relations_values'][$relation['id']]['new_relation_name'] = array(
'#type' => 'machine_name',
'#states' => array(
'visible' => array(
':input[name="relations[relations_values][' . $relation['id'] . '][relation_type]"]' => array(
'value' => 'new',
),
),
),
'#default_value' => !empty($settings['relations']['relations_values'][$relation['id']]['new_relation_name']) ? $settings['relations']['relations_values'][$relation['id']]['new_relation_name'] : '',
'#machine_name' => array(
'exists' => 'crm_core_data_import_relation_exist',
),
'#required' => FALSE,
);
$form['relations']['relations_values'][$relation['id']]['destination_entity'] = array(
'#type' => 'value',
'#value' => $relation['contact_type_b'],
);
$form['relations']['relations_values'][$relation['id']]['destination_entity_markup'] = array(
'#markup' => $relation['contact_type_b'],
);
}
}
}
}