Free tagging is no doubt the main use for community tags, but there are cases where we want to allow users to select from an admin-defined set of tags.

Attached is a rough patch for adding support for regular taxonomies. We follow the convention in taxonomy module of having a taxonomy array which is an array of tids for a regular vocabulary and, for a free tagged vocabulary, has a single item with the key 'tags'.

Needs further testing and work, I think I've broken freetagging in t he patch, I'll fix it up soon. Javascript doesn't work with regular taxonomies (but maybe that's okay). Initial feedback on the idea would be great. Does this fit with people's idea of community tags?

Comments

Steven’s picture

Status: Needs review » Postponed

Sorry, but this makes an already complicated and ugly module even worse. I'm not going to commit anything like this until core taxonomy gets refactored, so the community tagging data model can be disconnected from the tagging UI.

nedjo’s picture

StatusFileSize
new23.84 KB

I'm not going to commit anything like this until core taxonomy gets refactored

Understood. Is there a relevant patch in the queue?

Here for the record, and potentially for future reference or reworking, is a completed patch.

Changes since the last iteration:

1. Includes javascript for regular taxonomies.
2. Fixed errors in previous patch that broke free tagging.

I've also included support for tagging on node teasers. This required some reworking of the data model, which was previously limited to a single node's data. Is this of interest? If so, I could factor it out into a separate patch.

Some issues with the patch:

1. Reliance on hook_footer() to output JS settings. This assumes the hook is called after content is generated but before JS is generated, which is true for PHPTemplate themes but potentially not for regular PHP themes.

2. Need an image, add.png, equivalent to the existing delete.png.

3. The Javascript implementation could use some further design work. I've implemented it as two rows of tags, the ones available and the ones already applied. Available tags are labeled 'add to tagname', while already applied ones are labelled 'remove from tagname', where tag name is the term name.

4. In the Javascript, I'm explicitly passing around references in some places, e.g., nid and elt in

var addHandler = function (nid, elt)

Likely the code could be improved to avoid needing this explicit passing.

Because I need this functionality for a current project, I'll probably implement this as a separate module that extends community_tags if feasible.

nedjo’s picture

StatusFileSize
new23.76 KB

Old version had a debugging line left in.

nedjo’s picture

I've rewritten the patch as a new module, community_tagsrv, Community Tags Regular Vocabularies, and committed to Drupal CVS, http://cvs.drupal.org/viewcvs/drupal/contributions/modules/community_tag.... I'm hoping this can be merged back in with Community Tags and have written it to avoid any conflicts and facilitate merging in.

I'm considering whether I should release community_tagsrv as a module, with a note saying it's intended to be merged into Community Tags when possible. Any red flags or concerns or reasons not to?

Attached is an updated patch with some small bug fixes from the previous patch.

Steven’s picture

At the moment, there isn't enough functional code re-use (e.g. in the JS) to justify this patch IMO. The only reason they are grouped together is because they both need to do annoying heavy lifting to get around taxonomy's silly limitations. That is IMO not reason enough to merge it.

I'm also worried about the UI concerns, because the module uses the word "tags" everywhere, yet some things apply to terms too (e.g. "edit own tags" permission).

I also don't see why you added a static cache mechanism for the drupal_add_js(). This function checks this for you, and will even merge arrays recursively.

nedjo’s picture

Thanks for taking the time to look at this more.

At the moment, there isn't enough functional code re-use (e.g. in the JS) to justify this patch IMO.

Agreed particularly for the JS that the code reuse could be improved. I could have a go at writing a single set of methods that could process both regular and freetagging vocabularies. This would probably mean moving to a model where data are stored client side in a form that meets both needs, i.e., has both the tid and the term name. Of course, for freetagging vocabularies this requires server interaction when adding tags.

I'm also worried about the UI concerns, because the module uses the word "tags" everywhere, yet some things apply to terms too (e.g. "edit own tags" permission).

Agreed that this is a challenge. Another case is "'You have already tagged this post. Your tags: ". Possible approaches would be (a) move to more generic wording that applies to all, like "categorize content" instead of "tag content"; (b) have parallel wordings for each, (c) leave it as it is, assuming that in this particular case both types of categorizing can be called "tagging".

I can't think of anything for (a) that isn't awkward. A full (b) approach would mean e.g. introducing superfluous permissions. So I'm not sure what's best. I guess my inclination is (c).

I also don't see why you added a static cache mechanism for the drupal_add_js().

It's the recursive merging that's the issue. Initially, when I had the function called once for each node on the page, I ended up with multiple values for keys, one for each time the function was called, e.g. add: ['add to', 'add to', 'add to']. This shouldn't be a big concern in hook_footer(), as it's unlikely this will be called twice, but I left it in just in case.

nedjo’s picture

StatusFileSize
new24.06 KB

Here's an improved patch.

I've completely rewritten the Javascript to integrate as much as possible the regular and freetagging vocabulary handling, introducing a single set of methods that apply to both.

Other changes include:

1. Merging in new freetagging tags is now done on the client rather than on the server. This enables a single post method.

2. Regular vocabulary tags are in one ul element rather than separating them out into two.

3. Removed use of hook_footer(). Instead, an initial array is declared using a static variable for the settings, then individual node data are added in a way that will merge.

I'm feeling (I guess taking the time to rewrite the patch suggests so!) that this does make sense as a single module. We have these two types of vocabularies in Drupal. Yes, they require distinct server and client side treatment. But they are both forms of tagging. The data storage needed is identical.

On the PHP side, most of the complexity of the current module is to handle the freetagging. In comparison, the code for regular vocabularies is relatively straightforward. Adding regular vocabulary support increases the .module file by under 10% is size.

Just finished this redraft, it seems to basically work but could use some more testing.

nedjo’s picture

StatusFileSize
new23.95 KB

Minor fixes from previous version. Fixed parse error, removed some code no longer needed in the JS callback.

nedjo’s picture

StatusFileSize
new23.95 KB

Minor changes to JS to fix IE errors. IE didn't like a variable being named class or an extra comma at the end of an object list.

patchak’s picture

HI Nedjo,

I applied your patch to test it out, and it applied cleanly. I did not find any errors. I used it with a normal vocab with a couple of terms, and I found the interface to be surprising. I expected a dropdown menu where you can select the term you want to apply. The interface you choose "click to apply" is very interesting as well. Anyways everything seems to work smoothly, also in freetagging.

Btw, I love the option to have the tag form directly on the teaser even in freetagging, but I have two small feature requests...

1) Would be nice if the tagging section was in a collapsed field on the teaser, so people could open it and then tag.... At the moment it seems to really take a lot of place on the teaser with the 'all tags' and "my tags" sections... It would be interesting for the teaser view to have only the "my tags" shown, since all the tags are already displayed in the $terms section on the teaser.

2) This is related to the 1), as I think it would be nice to be able to let users tag from the teaser even if 'inline' is not chosen in the setup. For example I'd love to see the tagging form inline in the teaser, but in the block for the full view. So I guess the teaser setting should be independant from the 'on page' settings.

Voilà, as for the rest, like I said all seems to run pretty smoothly.

Thanks!
Patchak

nedjo’s picture

Thanks for the review!

I expected a dropdown menu where you can select the term you want to apply.

Turn off Javascript and that's just what you'll see ;) I based the JS interface on what's already there for freetagging.

We could consider, though, keeping the select, or making that optional, or dependent on the number of tags. Where there are only a few tags having them directly clickable seems to make sense, but I see that having many would clutter up the page.

That said, I'm not planning to work further on the patch unless its status is changed from postponed. If and when core taxonomy is rewritten (probably at least many months from now) enough changes will have occurred in the module that the patch will no doubt require rewriting from scratch.

patchak’s picture

Hi Nedjo,

I think the ideas of this patch are good, and the tagging directly on the teaser is a nice feature. have you though about my suggestion to put the tagging into a collapsible form??

Also, why not just publish this as a new module if the maintainer does not want to insert it??

Later,
Patchak

nedjo’s picture

Steven is right to hesitate to apply this patch. Community tags is complex, and, whatever my efforts to minimize additional complexity, this patch would make the module more difficult to maintain, expecially as I've completely rewritten the JS. I wanted to do what I could to address issues, but I still completely accept the 'postponed' status.

I did try writing this as a separate module, see http://drupal.org/node/140964#comment-241308. I didn't like the result, for some of the same reasons. If doing this in the same module adds complexity, doing it in a different module that builds on community_tags is positively messy.

So, it seems, the idea can wait until if and when community tags settles out and is ready for significant additions.

(Meantime, for the project I intended this for, I'm going to write a small custom solution instead.)

nedjo’s picture

Steven's recent patch to add AJAX to views_bookmark, http://drupal.org/node/141017, means that pretty much the same functionality can be achieved through that module.

KentBye’s picture

Earlier in this thread, nedjo said, "I've also included support for tagging on node teasers. This required some reworking of the data model, which was previously limited to a single node's data. Is this of interest? If so, I could factor it out into a separate patch."

I added another feature request hoping that the tagging nodes via their teasers can be broken out into a simpler and less complex patch.

mlncn’s picture

I'd like to order a paid subscription to this issue ;-)

I'm the Community Managed Taxonomy summer of code student - see my site and CMT on d.g.o, and feel free to file feature requests at CMT's drupal.org project.

CMT would allow users to add tags to hierarchical vocabularies, but would allow for thresholds of support to be reached before putting this information into taxonomy, and would not have the idea of "my terms" that Community Tags has (at least not by default and not in the same sense, as multiple users will generally be voting on any particular term, location, or synonym).

There is clearly, however, a great deal of overlap, and given the interest in specific functionality such as this feature request and patch, I would love to hear people's thoughts on the possibility/impossibility of splitting functionality into submodules that can be shared. Right now I don't see much except in the AJAX-enhanced interface used here that I can't wait to steal.

Just letting people know what I'm doing, I'll be asking specific folks more specific questions once I know what I'm doing.

KentBye’s picture

There's a bug in nedjo's patch whenever a node doesn't have any initial tags, then the o.tags[nid] is an empty object with a value of "[object Object]" and it gives the following error:

o.tags[nid].push is not a function
addHandler("3693")
(no name)()
e(click clientX=0, clientY=0)
o.tags[nid].push(textfield[0].value);

community_tags.js (line 45)
community_tags.js (line 60)
community_tags.js (line 67)
jquery.js (line 2)

Another version of this bug is also in the regular version of community_tags, and is described in this issue It was fixed in the trunk version by initializing the o.tags to an empty array, and I took a similar approach to getting it to work.

In community_tags.js, I changed this code snippet from:

      // Prepare the add Ajax handler and add the button.
      var addHandler = function (nid) {

to:

      // Prepare the add Ajax handler and add the button.
      var addHandler = function (nid) {
        if(o.tags[nid].toString() == "[object Object]") {
          o.tags[nid] = "";
        }

And it works now with tagging nodes in teasers.