This module is excellent. I have one nagging curiosity however: why I am not able to use the very same Taxonomy terms I just created and simply "tag" the users?

In using Drupal 7 I am creating some views to go along with my taxonomy access. For example : a list of "Teams". I use tac_lite to define what members of those teams can see and do. Then, I wish to show lists of those teams. Great. can do that by listing terms. Say I have two teams: Red Team and Blue Team.

Then I wish to display users who belong to a team. I went to setup a view to: find users with term id = "Blue Team". The data is not stored as a term reference though. It appears to be saved in the user data blob field. Now I have to create another term reference field.

Is it possible to have the storage mechanism use taxonomy in the same way for nodes and for users? Create terms. Tag your nodes. Tag your users.

Perhaps it is not that simple? Or at least, allow a setting, or hook where I can tell the system: Also add the selected taxonomy term(s) to the user.

Comments

Dave Cohen’s picture

Issue tags: +tac_lite-volunteer

In D6 you could not tag users.

Do you have the PHP skills to add this feature? It would be something like this...

1. A checkbox on a tac_lite scheme page, "grant terms with which user is tagged?"

2. If checked, when computing the user's grants, include their taxonomy tags in addition to anything that might be in their data array.

Would be a nice feature!

quinnmerio’s picture

Thank you, Dave - much appreciate your response to this. I will not have time to add this as a feature, unfortunately - client deadlines loom.

svdhout’s picture

StatusFileSize
new3.56 KB

I took a shot at adding this feature.
Users that have a taxonomy reference on their profile are given grants.

What i did to get it working:

Add an extra option to the scheme config

function tac_lite_admin_scheme_form( ...
  $form['tac_lite_config_scheme_' . $i]['user_terms'] = array(
      '#type' => 'checkbox',
      '#title' => t("Use account term reference for grants."),
      '#default_value' => $config['user_terms'],
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );
    
    $form['tac_lite_config_scheme_' . $i]['user_terms_field'] = array(
      '#type' => 'select',
      '#title' => t("Term reference field"),
      '#options' => tac_lite_get_fields_for_type('user', 'user', 'taxonomy_term_reference'),
      '#default_value' => $config['user_terms_field'],
      '#states' => array(
        'visible' => array(
          ':input[name="tac_lite_config_scheme_' . $i . '[user_terms]"]' => array('checked' => TRUE),
        ),
      ),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );
...

If you tick 'Use account term reference for grants.', a select box opens up.
This is used to define which term_reference will be used to assign grants from.

A function tac_lite_get_fields_for_type($entity_type, $bundle, $field_type) was created to retrieve all fields for a given entity and field_type:

/**
 * Helper function to return all term reference fields for a bundle
 * @param $entity_type
 *   The entity type
 * @param $bundle
 *   The bundle name
 * @param $field_type
 *   The field type
 */
function tac_lite_get_fields_for_type($entity_type, $bundle, $field_type) {
  $instances = field_info_instances($entity_type, $bundle);
  foreach ($instances as $instance) {
    $field_info = field_info_field($instance['field_name']);
    if ($field_info['type'] == $field_type) {
      $fields[$instance['field_name']] = $instance['label'];
    }
  }
  return $fields;
}

Next i added the grants themself inside _tac_lite_user_tids:

function _tac_lite_user_tids($account, $scheme) {
...
// use the user term field for grants
  if ($config['user_terms']) {
    $field_name = $config['user_terms_field'];
    $account = user_load($account->uid);
    $items = field_get_items('user', $account, $field_name);
    if(is_array($items)) {
      foreach ($items as $tids) {
        if (count($tids)) {
          $ctids[] = $tids['tid'];
          $grants = array_merge($grants, $ctids);
        }
      }
    }
  }
...

While i was at it i also fixed a notice i got on the users page:
changed

if ($form['#user']->data[$config['realm']]) {

to

if (isset($form['#user']->data[$config['realm']])) {

I've created a patch using svn, so i'm not sure if it will work for git.
I got to read up on that topic

Drupaled-1’s picture

Hello,

I read this post a couple times over to make sure I understood what the request was, but I apologize if this recommendation is not exactly what you are looking. The original post references Drupal 7, but Dave's first reply references Drupal 6. My post is for anyone using Drupal 6 and needs to tag users.

The site I am currently developing also required the ability to tag the users with taxonomy terms alongside being able to use them for TAC Lite.

I found the following module developed called 'User Terms'

It is located here: http://drupal.org/project/user_terms

I hope this may help?

kaizerking’s picture

@svdhout- It seems this only works for D7 core profile,can you make it for profile2 support and field collection fileds, please?

vladimiraus’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Thank you for contribution. 👍
Drupal 7 is no longer supported. 🤷‍♂️
Closing as outdated. 🔐