Hi,

So far I'm really happy with User Term's, its helped me a lot with a particular problem I was having and had been trying to solve for ages.

Would it be possible to allow user's to free tag when they select their user term on their accounts, and so actually create tags if an appropriate tag is currently available from the listed vocabulary? If this would allow users to create a unique user term when they register with the site it would be fantastic!

Thanks

Comments

joachim’s picture

This is definitely a desirable feature.

However, it's not something I need for my current project using User Terms, and the other maintainer of this module isn't doing much work on it at the moment as far as I know.

If someone else works on this and posts a patch, I will review it -- the defunct User Tags module had this functionality so it shouldn't be too much work to bring that over. Here's a good place to start: http://drupal.org/node/245582

Alternatively, I am available for paid customization of this (and other ;) modules.

anasynth’s picture

Just for the record I was able to mimic the functionality I described above.

I added a text field to the profile page which allowed users to enter a new tag if one was not currently available on the site. Some php then checks for errors etc and adds the tag to the correct vocabulary using a function from the taxonomy module. The tag is then available for selection from the list provided by User Terms.

By the way, I think that above I meant:

Would it be possible to allow user's to free tag when they select their user term on their accounts, and so actually create tags if an appropriate tag is currently unavailable from the listed vocabulary?

I'm afraid that I'm very new to drupal and programming in php so I won't be able to provide a patch, but I'd be willing to help as far as I'm capable.

Cheers

joachim’s picture

That's not really the right way to do it.
Best way is to copy the way taxonomy module does it itself, reusing the functions where possible, and where not, copying the code with the necessary modifications. I only took a quick glance at the code for User Tags, but that seems to be the way that module does it.

Babalu’s picture

subscribing

p4trizio’s picture

subscribe

bachbach’s picture

+1

hokuspokus’s picture

one more for "I can't wait for this"

joachim’s picture

See my comment in #1 :)

mstef’s picture

Going to start working on this now

mstef’s picture

Looks easy - should be done by the end of the day.

hokuspokus’s picture

Great! You're a lifesaver if you are able to get this done!

mstef’s picture

Status: Needs work » Needs review
StatusFileSize
new3.59 KB

Ooooh yea..

Enjoy

Someone please review cause I chopped this thing up real fast.

Everything works fine for me so far. This widget on the profile edit form will now reflect whichever type you choose in the vocabulary settings - tags, select, etc.. Entering a new tag will create the term.

I might do a little work later on with changing how they show up on the main profile view (cause they're ugly and non-linked right now).

I'd like to have this pushed into the next release if possible. I'd be up to maintaining if the current maintainer wants that.

EDIT: Get the patch uploaded a few comments below

joachim’s picture

Status: Active » Needs work

Sounds great!

But could you post this as a patch rather than an archive please?

mstef’s picture

Status: Needs review » Needs work

edit

mstef’s picture

I'm going to create a patch now. Don't use the previously uploaded module. I found a small change I need to make in it anyway.

Be back in a minute

mstef’s picture

StatusFileSize
new5.39 KB

Patch!

mstef’s picture

mstef’s picture

Can someone review/test?

joachim’s picture

Status: Needs review » Needs work

I need to sit down and spend some time with this patch, as it affects the same parts of the code as #656428: Multiple vocabularies assigned to abitrary profile categories (which I need to reroll...).

Some initial observations:

+++ user_termsNew.module	2010-04-20 14:13:34.000000000 -0400
@@ -244,39 +244,67 @@ function user_terms_form_profile($edit, 
+          // Indicate that we're using free tags
+          $form['user_terms']['user_terms_tags_' . $vocabulary->vid] = array(
+            '#type'=> 'hidden',
+            '#value' => TRUE,
+          );

I'm not keen on setting a second hidden value. Could we adapt $form['user_terms_vids'] to suit this?
Perhaps instead of just storing $vids, store an array of $vid => WIDGETTYPE?

+++ user_termsNew.module	2010-04-20 14:13:34.000000000 -0400
@@ -244,39 +244,67 @@ function user_terms_form_profile($edit, 
-      // Set a hidden value on the form so that we can check in user_terms_save_profile()
-      // that we've actually come from the account edit form.
-      $form['user_terms_vids'] = array(
-        '#type' => 'value', 
-        '#value' => $vids,
-      );
+    // Set a hidden value on the form so that we can check in user_terms_save_profile()
+    // that we've actually come from the account edit form.
+    $form['user_terms_vids'] = array(
+      '#type' => 'value', ¶
+      '#value' => $vids,
+    );
 
-      return $form;
-    }
+    return $form;

I'm not sure why these bits getting unindented.

Powered by Dreditor.

mstef’s picture

At the moment, this causes problem when free tags are used on the user registration form. I'll check it out in a little..

mstef’s picture

Can't figure out the point of this: user_terms_form_profile()

if (!$register) {
  $user = user_load(array('uid' =>  $account->uid));
  $default = empty($user->user_terms) ? array() : array_keys($user->user_terms);
}

The param $account is your user. $user is never used afterwards in the code.

$default is loaded above, but also never used, as $default_terms gets loaded with the vocab defaults.

Am I missing something?

mstef’s picture

Hitting /taxonomy/autocomplete/%vid requires 'access content' perms and that check wasn't added to the patch.

mstef’s picture

StatusFileSize
new5.57 KB

Fixed!

joachim’s picture

+++ user_termsNew.module	2010-04-28 09:24:21.000000000 -0400
@@ -244,39 +244,72 @@ function user_terms_form_profile($edit, 
+          if (!user_access('access content')) {
+            return;
+          }

You're just returning nothing if the user can't see the autocomplete? Wouldn't it be better to just show a textfield without the autocomplete doodad?

Powered by Dreditor.

joachim’s picture

re:#21. That looks like old cruft. I'm filing a new issue to get rid of it :)

mstef’s picture

re:#24. That seemed like the best way to handle it (for now). I suppose a text field is a pretty good idea, but in my mind, I thought just to let the user fill it out on their profile. Tagging yourself on registration didn't seem necessary. Now that I think of it, even if it's not set to tags, a user without 'access content' perms shouldn't be able to see a select field that's loaded with tags too.

ah I'll fix it later.

Maybe just completely scrap from the registration form all together? Regardless, once we get rid of that pointless code I mentioned above, we can remove $register as a param, as I don't see it being used anywhere else. I'm going to hold off a little on creating yet another patch, as now we're straying a little far from free tagging. Maybe we can agree on these few topics, push my patch with these fixes into a new release?

joachim’s picture

I've dug a little deeper into the 'access content' permission thing.

Users need that permission not just for tagging autocomplete, but to access taxonomy/term/x and indeed anything to do with taxonomy.
So technically, we shouldn't show *any* taxonomy form to a user without that permission. This really needs a new issue: #784248: check 'access content' permission.

joachim’s picture

Regarding release, what I think I'd like to do is get these issues closed in the following order:

- #656428: Multiple vocabularies assigned to abitrary profile categories -- this may affect your patch here
- #784248: check 'access content' permission
- this one
- #784146: Useless code in user_terms_form_profile

hokuspokus’s picture

Any updates on Free tagging?

joachim’s picture

What I said in #28 still stands. There is a patch at #656428: Multiple vocabularies assigned to abitrary profile categories that needs testing. The sooner people help test it -- and that means you -- the sooner we get to a release.

joachim’s picture

Okay, the following are now in:

- #656428: Multiple vocabularies assigned to abitrary profile categories
- #784146: Useless code in user_terms_form_profile

The patch above can now be rerolled against the current code and then perhaps all the +1s can help with testing!

myha’s picture

StatusFileSize
new5.61 KB

Rebuild patch for current code.

abudev’s picture

Hi, I used #32 patch and i get this error when i click on the tag with autocomplete:
An HTTP error 0 occured - taxonomy/autocomplete/4

I gave to anonimous user all permissions and nothing changed. Is there something wrong with permissions? I tried everything.. Thanks

abudev’s picture

I found a workaround, removed my base_url and work now. I'll do more testing with the patch, please excuse the inconvenience.

joachim’s picture

Patch works great!

There are a few code tweaks I'd like to see before I commit it:

+++ user_termsNew.module	2010-07-14 11:12:30.000000000 +0300
@@ -258,39 +258,72 @@ function user_terms_form_profile($edit, 
-      // Set a hidden value on the form listing the vocabularies we are editing
...
 
-      return $form;
-    }
+    return $form;

Why is this moving this out of the if (!empty($vids)) condition?

+++ user_termsNew.module	2010-07-14 11:12:30.000000000 +0300
@@ -311,12 +344,38 @@ function user_terms_save_profile(&$edit,
+    if ($edit['user_terms_tags_' . $vid]) {
...
-      $user_terms[] = $edit['user_terms_' . $vid];

This should be the master switch on a particular vid. Test 'user_terms_tags_' . $vid below this to see how to handle the vocab.

Powered by Dreditor.

myha’s picture

StatusFileSize
new5.06 KB

I'm not a author of the patch but I think that return $form should be moved into if (!empty($vids)) condition. Also unset $edit['user_terms_tags_' . $vid] variable to not store in the data user property. Attach patch with this changes.

joachim’s picture

Thanks for taking care of that myha :)

I'm working on a few things at the moment...

          // Free tagging requires certain content permissions for autocomplete to work
          if (!user_access('access content')) {
            return;
          }

Bailing on the whole form? There may be other vocabs!
But in fact, subsequent to this patch first being written, I put a check for 'access content' on the whole user terms fieldset.

Now there actually is a corner case here -- if your users can't access content, you MIGHT still want them to tag themselves but WITHOUT the autocomplete. But this seems to me to be rather a bizarre case, so I think we should leave it off. If someone wants this they can provide a subsequent patch :)

          $form['user_terms']['user_terms_tags_' . $vocabulary->vid] = array(

I don't really like this. For starters it's not the same format as the other hidden value we use (and BTW -- use 'value' and not 'hidden' as the type for this sort of thing).

I am debating whether to fold this into the existing $form['user_terms_vids'], by setting the key as 'tags', so you'd have:

1 => 1 // just a regular vocab
2 => tags
7 => 7

Pondering whether this is smart or hacky... :)

joachim’s picture

Status: Needs work » Needs review

Here's a new patch with all those changes.

Please test!

As there are quite a few combinations of settings for this module, I'd like it if at least a couple of people test the patch. Try several vocabs, profile categories, registration, etc etc

Once this gets in I'll roll a 1.2 release :)

yeputons’s picture

And where is the patch? :)

joachim’s picture

StatusFileSize
new6.71 KB

Oops.

naden’s picture

Patch runs without hassle. Thx!

doublejosh’s picture

Status: Needs work » Needs review

Might be off topic here but, sure would be nice if User Terms could play well with Taxonomy Super Select for changing to either the: radio, checkbox, or freetag plus checkbox widgets!

joachim’s picture

@doublejosh: yup, that would be best filed as a separate issue :)

joachim’s picture

Status: Needs review » Fixed

Ok, one review and no problems reported. This patch has been sitting around long enough; I'm committing it.

Thanks to mikestefff and myha for working on this and to everyone else who's contributed by reviewing or testing.

#617088 by mikestefff, myha, joachim: Added support for free tagging.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.