You are here

function crm_core_user_sync_admin_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_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 10

Code

function crm_core_user_sync_admin_form($form, &$form_state) {
  $form = array();
  $roles = user_roles(TRUE);
  $types = ContactType::loadMultiple();
  $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_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;
}