You are here

function crm_core_user_sync_edit_relation_form in CRM Core 8.2

Same name and namespace in other branches
  1. 7 modules/crm_core_user_sync/crm_core_user_sync.admin.inc \crm_core_user_sync_edit_relation_form()

Contact->User relation edit form.

1 string reference to 'crm_core_user_sync_edit_relation_form'
crm_core_user_sync_menu in modules/crm_core_user_sync/crm_core_user_sync.module
Implements hook_menu()

File

modules/crm_core_user_sync/crm_core_user_sync.admin.inc, line 312

Code

function crm_core_user_sync_edit_relation_form($form, &$form_state, $relation) {
  if (empty($relation)) {
    drupal_set_title('Create a new relation');
    if (!empty($_GET['uid'])) {
      $user = user_load($_GET['uid']);
      $disabled_user_field = !empty($user);
    }
    if (!empty($_GET['contact_id'])) {
      $contact = Contact::load($_GET['contact_id']);
      $disabled_contact_field = !empty($contact);
    }
  }
  else {
    drupal_set_title('Edit relation');
    if (!empty($relation->endpoints[LANGUAGE_NONE][0]['entity_id'])) {
      $user = user_load($relation->endpoints[LANGUAGE_NONE][0]['entity_id']);
    }
    if (!empty($relation->endpoints[LANGUAGE_NONE][1]['entity_id'])) {
      $contact = Contact::load($relation->endpoints[LANGUAGE_NONE][1]['entity_id']);
    }
  }
  $form['relation'] = array(
    '#type' => 'value',
    '#value' => $relation,
  );
  $form['description'] = array(
    '#type' => 'item',
    '#markup' => t('You can edit the details of a contact record to user account relationship using the following form.'),
  );
  $form['contact'] = array(
    '#title' => t('Contact record'),
    '#type' => 'textfield',
    '#default_value' => empty($contact) ? '' : $contact
      ->label() . " [contact_id:{$contact->contact_id}]",
    '#disabled' => empty($disabled_contact_field) ? FALSE : TRUE,
    '#autocomplete_path' => 'admin/config/crm-core/user-sync/contact-to-user-management/contact-autocomplete',
  );
  $form['user'] = array(
    '#title' => t('User record'),
    '#type' => 'textfield',
    '#default_value' => empty($user) ? '' : $user->name . " [uid:{$user->uid}]",
    '#disabled' => empty($disabled_user_field) ? FALSE : TRUE,
    '#autocomplete_path' => 'admin/config/crm-core/user-sync/contact-to-user-management/user-autocomplete',
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if (!empty($relation)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  $form['actions']['cancel'] = array(
    '#markup' => l(t('Cancel'), 'admin/config/crm-core/user-sync/contact-to-user-management'),
  );
  return $form;
}