Closed (won't fix)
Project:
User Tags
Version:
5.x-1.x-dev
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
8 May 2007 at 08:57 UTC
Updated:
3 Feb 2013 at 18:04 UTC
I made this patch to auto tag users content based upon their user tag. I used a location tag to tag each user. then all new content is defaulted to their location tag. if the user posts into a organic group the content is tagged with the group's location.
##Instructions
Create a single select taxonomy
Edit the following code with the taxonomy $vid (in my case the $vid was 1)
select that taxonomy to be used for user tags
!!The following code goes into taxonomy.module
This code needs more work. It is working for me at the moment so I am posting it in case anyone would like to implement something similar.
function taxonomy_form_alter($form_id, &$form) {
//.
//.
//.
//+++++Taxonomy.module around line 713+++++++++++
else {
// Extract terms belonging to the vocabulary in question.
$default_terms = array();
foreach ($terms as $term) {
if ($term->vid == $vocabulary->vid) {
$default_terms[$term->tid] = $term;
}
}
/*+++++++++++ADD(replace) starts from here++++++++++++++++++*/
//This sets the default vocab term based on node id . I.E. "37" or "38"
//TODO : Must change $_Location_vid to match the location taxonomy!!
if (!(arg(2) == 'edit')){
$_Location_vid = 1;
//This is for setting the default vocabulary term based on termid passed by the URL
/*if ($_GET['default_id'] != "") {
$default_terms[$_GET['default_id']] = $_GET['default_id'];
}
*/
//we want it to grab the ID of the parent group and set it to default
if ($_GET['gids'] != "") {
// NOTE : Only works to default to a single taxonomy term (Probally the lightest term)
$groups_node_id = $_GET['gids'][0];
$location_keys = array_keys(taxonomy_node_get_terms_by_vocabulary($groups_node_id, $_Location_vid, $key = 'tid'));
$default_terms[$location_keys[0]] = $location_keys[0];
//maybe someday we will need to assign multiple default terms
/*foreach ($location_keys as $lv_key){
$default_terms[$lv_key] = $lv_key;
}
*/
} else {
//the post is not part of a group, lets check the users location and default the post to the users location
//requires the user tags module
global $user;
$location_tag = user_tags_get_terms_by_vocabulary($user->uid, $_Location_vid, $key = 'tid');
$location_keys = array_keys($location_tag);
$default_terms[$location_keys[0]] = $location_keys[0];
}
}
/*+++++++++++++ADD(replace) ends here++++++++++++++++*//End hack
$form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help);
$form['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
$form['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required;
}
Comments
Comment #1
flk commentedhacking core is a bad idea mate :/
will have a closer look at the code after my exams... to see if we can attack it another way.
Comment #2
markDrupal commentedI figured that much. It was my first bit of coding in Drupal a few months ago. But now I have a bit more experience. It may be possible to move the code over into User_tag_form_alter() and only have a line of two of code to change. Any help would be appreciated, but I doubt I will have the time to get around to it for a month or two.
Comment #3
cimo75 commentedHi
(long time uh?)
I d need this for D6, anybody out there?
Simone
Comment #4
flk commentedyou probably want to have a look at this other module.
http://drupal.org/project/user_terms
They use the same tables etc.
Comment #5
cimo75 commentedHi
yes sorry I forgot to mention that I already use http://drupal.org/project/user_terms , what I d like is the same function as explained in this post.
Simone
Comment #6
pomliane commentedThis version of User Tags is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.
This issue has been automagically closed by a script.