function crm_core_user_sync_admin_form in CRM Core 7
Same name and namespace in other branches
- 8.2 modules/crm_core_user_sync/crm_core_user_sync.admin.inc \crm_core_user_sync_admin_form()
Admin form.
1 string reference to 'crm_core_user_sync_admin_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 6
Code
function crm_core_user_sync_admin_form($form, &$form_state) {
$roles = user_roles(TRUE);
$types = crm_core_contact_types();
$types_options = array();
foreach ($types as $key => $type) {
$types_options[$key] = $type->name;
}
$rules = variable_get('crm_core_user_sync_rules', array());
uasort($rules, 'crm_core_user_sync_weight_cmp');
$form['crm_core_user_sync_description'] = array(
'#markup' => t('CRM Core User Synchronization can automatically create contact records associated with user accounts under certain conditions.'),
);
$form['crm_core_user_sync_rules'] = array(
'#type' => 'container',
);
$form['#tree'] = TRUE;
foreach ($rules as $key => $rule) {
$form['crm_core_user_sync_rules'][$key]['role'] = array(
'#markup' => $roles[$rule['rid']],
);
$form['crm_core_user_sync_rules'][$key]['contact_type'] = array(
'#markup' => $types_options[$rule['contact_type']],
);
$form['crm_core_user_sync_rules'][$key]['enabled'] = array(
'#markup' => $rule['enabled'] ? 'Yes' : 'No',
);
$form['crm_core_user_sync_rules'][$key]['weight'] = array(
'#type' => 'weight',
'#title_display' => 'invisible',
'#default_value' => $rule['weight'],
);
$form['crm_core_user_sync_rules'][$key]['operations'] = array(
'#theme' => 'links',
'#links' => array(),
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
);
$links =& $form['crm_core_user_sync_rules'][$key]['operations']['#links'];
$path = 'admin/config/crm-core/user-sync/' . $key;
$links['edit'] = array(
'title' => 'Edit',
'href' => $path . '/edit',
);
$links['delete'] = array(
'title' => 'Delete',
'href' => $path . '/delete',
);
if ($rule['enabled']) {
$links['disable'] = array(
'title' => 'Disable',
'href' => $path . '/disable',
);
}
else {
$links['enable'] = array(
'title' => 'Enable',
'href' => $path . '/enable',
);
}
}
$form['crm_core_user_sync_auto_sync_user_create'] = array(
'#type' => 'checkbox',
'#title' => t('Automatically create an associated contact when account is created'),
'#description' => t('When checked, this checkbox will automatically create new contacts when a new user account is created according to rules listed above. Rules will be processed in order until a new contact is created.'),
'#default_value' => variable_get('crm_core_user_sync_auto_sync_user_create', 1),
);
$form['crm_core_user_sync_auto_sync_user_match'] = array(
'#type' => 'checkbox',
'#title' => t('Match existing contacts when creating an account?'),
'#description' => t('When checked, CRM Core will attempt to match users accounts to existing contact records using the email address given for the user record. Please note, you need to configure a primary email field for contact records in order for this to work.'),
'#default_value' => variable_get('crm_core_user_sync_auto_sync_user_match', 1),
'#states' => array(
'visible' => array(
':input[name="crm_core_user_sync_auto_sync_user_create"]' => array(
'checked' => TRUE,
),
),
),
);
$form['crm_core_user_sync_wrapper'] = array(
'#type' => 'fieldset',
'#title' => t('Sync Current Users'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['crm_core_user_sync_wrapper']['user_sync'] = array(
'#type' => 'submit',
'#value' => t('Synchronize Users'),
'#submit' => array(
'crm_core_user_sync_admin_form_user_sync_submit',
),
);
$form['crm_core_user_sync_wrapper']['description_wrapper'] = array(
'#type' => 'container',
);
$form['crm_core_user_sync_wrapper']['description_wrapper']['description'] = array(
'#type' => 'item',
'#markup' => t('Click this button to apply user synchronization rules to all user accounts that are currently not associated with a contact in the system. It will create an associated contact record for each user according to the rules configured above. Warning: this cannot be undone.'),
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save changes'),
);
return $form;
}