function crm_core_relationship_form in CRM Core 8
Same name and namespace in other branches
- 8.3 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_form()
- 8.2 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_form()
- 7 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_form()
Form builder for CRM Activity forms.
File
- modules/
crm_core_relationship_ui/ crm_core_relationship_ui.pages.inc, line 70 - CRM Core Relationship UI Pages.
Code
function crm_core_relationship_form($form, &$form_state, $relation) {
// Ensure this include file is loaded when the form is rebuilt from the cache.
$form_state['build_info']['file'] = drupal_get_path('module', 'crm_core_ui') . '/pages/contact_activity.pages.inc';
$form_state['entity_type'] = 'relation';
$form_state['relation'] = $form_state['crm_core_relationship'];
unset($form_state['crm_core_relationship']);
if (isset($relation->crm_core_contact)) {
// Get the contact id of who is trying to add the activity.
$form['contact_id'] = [
'#type' => 'value',
'#value' => arg(2),
];
}
module_load_include('inc', 'crm_core_relationship_ui');
$form = [];
$form['relationship_type'] = [
'#type' => 'value',
'#value' => $relation,
];
$form['reverse'] = [
'#type' => 'value',
'#value' => $relation->reverse,
];
$form['relationship_type_label'] = [
'#type' => 'item',
'#title' => t('Relationship type'),
'#markup' => $relation->label,
];
foreach ([
0,
1,
] as $reverse_field) {
$contact_type_names = [];
foreach (crm_core_relationship_load_contact_types($relation, $reverse_field) as $contact_type) {
$contact_type_names[] = t($contact_type->name);
}
$contact_type_names = implode(', ', $contact_type_names);
if (isset($relation->crm_core_contact)) {
$form[$reverse_field ? 'destination_contact' : 'source_contact'] = [
'#title' => $reverse_field ? t('Destination contact name') : t('Source contact name'),
'#description' => t('Following contact types allowed: !types.', [
'!types' => $contact_type_names,
]),
'#type' => 'textfield',
'#default_value' => !($reverse_field ^ $relation->reverse) ? $relation->crm_core_contact
->label() . " [cid:{$relation->crm_core_contact->contact_id}]" : '',
'#disabled' => !($reverse_field ^ $relation->reverse),
'#required' => TRUE,
'#autocomplete_path' => 'crm-core/contact/' . $relation->crm_core_contact->contact_id . '/relationships/add/' . $relation->relation_type . '/' . $reverse_field . '/autocomplete',
];
}
else {
$form[$reverse_field ? 'destination_contact' : 'source_contact'] = [
'#title' => $reverse_field ? t('Destination contact name') : t('Source contact name'),
'#description' => t('Following contact types allowed: !types.', [
'!types' => $contact_type_names,
]),
'#type' => 'textfield',
'#default_value' => '',
'#required' => TRUE,
'#autocomplete_path' => 'crm-core/relationships/' . $relation->relation_type . '/' . $reverse_field . '/autocomplete',
];
}
}
$form['uid'] = [
'#type' => 'value',
'#value' => $relation->uid,
];
field_attach_form('relation', $relation, $form, $form_state);
unset($form['endpoints']);
$form['actions'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'form-actions',
],
],
'#weight' => 40,
];
// We add the form's #submit array to this button along with the actual submit
// handler to preserve any submit handlers added by a form callback_wrapper.
$submit = [];
if (!empty($form['#submit'])) {
$submit += $form['#submit'];
}
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save Relationship'),
'#submit' => $submit + [
'crm_core_relationship_ui_add_relationship_form_submit',
],
];
// Show Delete button if we edit activity.
if ($form_state['op'] == 'edit') {
$form['actions']['delete'] = [
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => [
'crm_core_relationship_ui_add_relationship_form_delete',
],
];
}
// We append the validate handler to #validate in case a form callback_wrapper
// is used to add validate handlers earlier.
$form['#validate'][] = 'crm_core_relationship_ui_add_relationship_form_validate';
// Add after build to set proper page Title as it
// got set by entity_ui_main_form_defaults.
// @see entity_ui_get_form().
$form['#after_build'][] = 'crm_core_relationship_form_after_build';
return $form;
}