There are 2 things I would like to see in this module which I think integration with a user taxonomy field would fix:
- Views integration (when there is a taxonomy field linked to the user, this is automatically integrated with views). We need this to show a list of users who have access to the same content.
- One page for user edit. There is a seperate tab to manage the TAC Lite terms. It would be nice to be able to edit the terms on the user create/edit form.

If it is possible to sync between a users taxonomy field and the TAC Lite terms of a user, there is a solution for both problems mentioned above. The downside is that you duplicate data (you have term references and TAC Lite which both store the same relation).

Comments

seanB’s picture

I added a custom module which keeps a taxonomy field and the tac_lite data in sync. Below is the code I use. The tac_lite scheme is hardcoded as well as the vocabulary and field name. Untill such a feature is added, this can be used as a workaround.

I hope that the project allows me to work on a solid patch for the module later...

/**
 * Implements hook_menu_alter().
 */
function custom_menu_alter(&$items) {
  // Remove tac_lite settings page because of sync with taxonomy field
  unset($items['user/%user_category/edit/tac_lite']);
}

/**
 * Implements hook_form_alter().
 */
function  custom_form_user_profile_form_alter(&$form, $form_state) {
  // Check if we are on a tac_lite settings page
  if(!isset($form['tac_lite'])){
    // Add function to sync tac_lite with taxonomy
    $form['#submit'][] = '_custom_sync_tac_lite';
  }
}

/**
 * Helper function for keeping taxonomy terms in sync with tac_lite.
 */
function _custom_sync_tac_lite(&$form, &$form_state){
  // Load user
  $account = user_load($form_state['values']['uid']);
  
  // Get all related terms for field
  $values = array();
  foreach($form_state['values']['field_user_groups'][LANGUAGE_NONE] as $term){
    $values[$term['tid']] = $term['tid'];
  }
  
  // Loop over all terms to create tac_lite array
  $vocabulary = taxonomy_vocabulary_machine_name_load('user_group');
  $terms = taxonomy_get_tree($vocabulary->vid, 0, null, true);
  $tac_lite = array();
  foreach($terms as $term){
    if(isset($values[$term->tid])) {
      $tac_lite[$term->tid] = $term->tid;
    }
    else {
      $tac_lite[$term->tid] = 0;
    }
  }
  
  // Save tac_lite array to user object
  $new_account = clone $account;
  $new_account->data['tac_lite_scheme_2'][1] = $tac_lite;
  user_save($account, (array)$new_account);
}