Can the associated node be assigned the taxonomy term?

ktnk - June 28, 2007 - 20:08
Project:Node Auto Term [NAT]
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Hi,

I am opening this as critical because I was about to import a boatload of content that used NAT and I realized that when a node is created, the associated category is indeed created, HOWEVER:
The new term is not assigned to the created node!

So when viewing the term, my node is not listed under this term.

This is a big drawback in my setup and I would like a solution or workaround asap since we are deploying soon.

Thanks a bunch,
ktnk.

#1

christopher_skauss - July 13, 2007 - 15:06

Forcing the user to go back to edit the node in order to assign it to the newly created term is a little bit unfriendly to the user. I agree this is a most valuable functionality. Is it in your plans to implement it?

#2

Christefano - November 26, 2007 - 22:21

I agree with everything said here. Is anyone interested in contributing or collaborating on this feature? I might have some time to put into this and would like to test the waters to see if this would benefit more than a handful of people.

#3

christopher_skauss - December 3, 2007 - 10:35

I would be glad to test it! I wish I could help with code but my skills are limited

#4

Harry Slaughter - April 26, 2008 - 17:49
Version:HEAD» 5.x-2.1

Subscribing.

I need this functionality too. If you're using panels2, which everyone soon will be :), this is a must have feature.

I'm looking into creating a patch. I'm just not sure if there's some solid reason the author did not include this functionality by default.

see also: http://drupal.org/node/194804

#5

eggthing - June 11, 2008 - 21:33

Yes, I'm realy hoping for this feature too. Something with computed field perhaps for the time being?

#6

leo.ruffini - June 12, 2008 - 11:26

Me too!!

#7

messenger - June 16, 2008 - 15:15

This is a good option to have available when syncing.
thanks

#8

molenick - June 26, 2008 - 18:37

I'd consider this feature essential as well. I've also had some problems trying to go back and associate the term to the original node - my drupal site will time out, and when I refresh the term is gone. This may have been with delete node->term on.

What sort of work would need to go into this?

#9

molenick - June 26, 2008 - 22:31

I create a little hack for this, I've only done a little testing and am not sure of the total system impact. It seems to work pretty simply but I'd definitely advise against trying it unless you know what you're doing.

Inside nat.module is a function called _nat_save_association that saves node id, term id and vocabulary id in a NAT-created table (called "nat") whenever a new node-type that's been set up with NAT has been created.

The problem that is occurring is that this same information (node id, term id) is not being stored in the normal taxonomy table for storing this information, "term_node".

My hack simply consists of doing an insert into "term_node" as well as "nat" since we have all the information we need to do both within this function.

I am fairly new to Drupal, does anyone know what the preferred method for rolling something into a module is? Ideally, this change would make this insert an option in the NAT module settings to turn on or off.

#10

Manuel Garcia - June 28, 2008 - 00:54

@ molenick - You can start by posting your code I guess

Suscribing, but not a developer myself... any heroes? - willing to test patches here!

#11

molenick - June 30, 2008 - 16:47

Sure, it's simple:

Replace the function _nat_save_association in nat.module with this:

<?php
/**
* Save node-term associations in the NAT table.
*
* @param $nid
*   Node ID of the node.
* @param $terms
*   NAT-terms of the above node.
*/
function _nat_save_association($nid, $terms) {
  foreach (
$terms as $term) {
   
db_query("INSERT INTO {nat} (nid, tid, vid) VALUES (%d, %d, %d)", $nid, $term['tid'], $term['vid']);
   
   
// 2008.06.26 // molenick //
    //----------------------------------------------------------------
    //  Added an additional insert into the term_node table so that
    //    the term for the $node->type being created is also associated
    //  with the node itself.
    //----------------------------------------------------------------
   
db_query("INSERT INTO {term_node} (nid, tid) VALUES ($nid, " . $term['tid'] . ")");
  }
}
?>

It's pretty straightforward, I don't know how to make a proper patch otherwise I would. I'm only using the NAT setting "Delete associated term if a node is deleted" and everything seems to be working fine after some light testing.

Also, I worked on making a NAT setting to turn this feature on/off but couldn't pull values out of the nat_config inside this function, I'll have to dig around a bit more to see if I can get it working.

Slightly off-topic: how do I subscribe to an issue?

#12

Manuel Garcia - June 30, 2008 - 16:59

Great, thanks molenick!

Answering your question on subscribing, you dont, basicaly you reply so that the thread gets listed in your user tracker page,
So in your case, you can just go to http://drupal.org/user/298111/track and see if anyone has replyed to the threads you have written to :)

#13

molenick - June 30, 2008 - 17:23

Gotcha, figured as much. :)

I created a patch, but for some reason Vista/UnxUtils is being a flaky so I can't properly test it, but I followed the direction using diff here (http://drupal.org/patch/create) and the patch file looks about right. Give it a whirl and let me know how it looks.

AttachmentSize
nat.associate_term_with_create_node.patch 810 bytes

#14

Zen - July 3, 2008 - 08:20
Status:active» needs work

This has to be an optional feature and requires updates to the configuration screen. Please also follow the other guidelines for patch creation including code and comment style etc.

Thanks,
-K

#15

molenick - July 3, 2008 - 19:10

I've gone ahead and made the changes as suggested. I had to create a third parameter for _nat_save_association to take in $node_type so that I could check to see if the NAT option to associate an auto-term with its parent node was on for a given type.

_nat_save_association is only called from two places - during node creation and during NAT syncing. Both of these should be tested in addition to node deletion, ensuring that data is cleaned up properly from the NAT and node_term tables.

Also, the language for this setting reads like this:

"Associate an automatically created NAT term with %TYPE parent node?"

where %TYPE is the node type. That description feels a tad clunky to me, if anyone has any suggestions for altering it feel free to suggest.

K, I'll leave the patch's status marked as "patch (code needs work)" until you look it over.

AttachmentSize
nat-155411-15.patch 3.45 KB

#16

brainchild - July 12, 2008 - 14:42

I think the patch proposed here is written a bit incorrectly. Currently module hooks the node_api and adds associations just before (or after) node is saved. So basically taxonomy is associated with the taxonomy core, so there is no need to do that twice using module. Another issue - you'll get a double-assigned taxonomy when have vocabulary set to allow multiple selections.

I reworked the _nat_save_association function a bit. Hopefully it'll be useful for you.

Ah, one more thing. You need to assign the "Module Weight" for NAT to something like 10 or so to make it running after the other modules.

<?php
/**
* Save node-term associations in the NAT table.  Optionally, associate the terms with a given node in the
* node_term table if the option is set for a given type in NAT's settings.
*
* @param $nid
*   Node ID of the node.
* @param $terms
*   NAT-terms of the above node.
* @param $node_type
*   The type of the node.
*/
function _nat_save_association($nid, $terms, $node_type) {
   
$nat_config = variable_get('nat_config', array());
    foreach (
$terms as $term) {
       
db_query("INSERT INTO {nat} (nid, tid, vid) VALUES (%d, %d, %d)", $nid, $term['tid'], $term['vid']);

    }
    if (isset(
$nat_config['node_term']["$node_type"])) {
       
$node_terms=taxonomy_node_get_terms($nid);
        foreach (
$terms as $term){
           
$vocabulary=taxonomy_get_vocabulary($term['vid']);
            if(
$vocabulary->multiple==0){
               
$_terms=taxonomy_node_get_terms_by_vocabulary($nid,$vocabulary->vid);
                foreach (
$_terms as $_term){
                    unset(
$node_terms[$_term->tid]);
                }
            }
           
$node_terms[$term['tid']]= new stdClass();
           
$node_terms[$term['tid']]->tid=$term['tid'];
        }
       
taxonomy_node_save($nid,$node_terms);
    }
}
?>

#17

dydecker - July 15, 2008 - 20:06

subscribing

#18

white-raven - July 23, 2008 - 13:12

I would like to humbly suggest a different implementation for this feature...

As far as I can tell, the whole point of the same-name term is to relate other nodes to the same-name node. What about implementing a feature that, without having to associate it with the term, the same-name node automatically appears as the first node in the same-name term's list; of course, you'd be able to turn this bahaviour off if you wish. This can be accomplished by modifying the taxonomy_term View, or by creating a module feature whereby NAT can be configured to "step in" to add the NAT node to the list right before displaying a NAT term's page. See also http://drupal.org/node/285125

I was thinking of working on this for 6.x once Views 2.x integration is established. Perhaps the current work wouldn't be thrown out if the "NAT node hooks to NAT term" implementation (discussed in this issue thus far) gets polished for 5.x, and this "automatic term view hook" idea gets developed for 6.x?

Thoughts?

#19

alex-and-r - July 24, 2008 - 09:15

I tested the function form #16 and got an error:

Missing argument 3 for _nat_save_association(), called in /my/site/adress/nat.module on line 656 and defined in /my/site/adress/nat.module on line 600

I've got drupal 5.7. installed if it matters.

UPDATE: Oh, it seems that it's I'm the one to blame, cuz, I think, I had to apply patch form #15 first and then had to replace the function... Poor me! )
But anyway! Can someone compose a normal patch from #15 and #16?

#20

alex-and-r - July 24, 2008 - 13:01

Hi, again!

I've applied the patch from #15 and then inserted function from #16 and got nothing... :(

I create a node of the type specified in NAT configuration to produce a category with the name of the node in a vocabulary. The category is created, but the created node is not associated with this category. I mean this node have no categories at all and I was expecting that he'll be categorized under newly created category!

Am I doing something wrong? Can anyone help?

#21

molenick - July 24, 2008 - 20:14

@brainchild - thanks for the update! I haven't used multiple selections for the stuff I've been doing so it got neglected.

@white-raven - I'm not sure I understand your proposed approach. Mine revolved around the idea of using multiple CCK types to store data around a "core" CCK type object. Basically, you'd create your core object and then associate other types with and pull it all together using views and the data group's taxonomy term. I think what your proposing would require storing the association between the initial NAT-node and its term-related children somewhere, which the core taxonomy tables do nicely with no additional work.

@alex-and-r -
#19: I'll see about rolling patches 15 and 16 together this weekend or next as my free time allows.

#20: It sounds like you are creating the node first and then the category? Here are a few simple setup steps (#word# designates a placeholder):

1) create CCK-type #NAT_NODE#.
2) create taxonomy vocabulary #NAT_VOCABULARY#.
3) while creating #NAT_VOCABULARY#, click the checkbox for #NAT_NODE# under types.
4) go to admin>>NAT. inside, click on #NAT_NODE# and in the vocabularies listbox click on #NAT_VOCABULARY#.
5) Enable whatever other options you want (I used delete and the one I added in #15) and save.

Now, when you create a node of type #NAT_NODE#, it should create a term in #NAT_VOCABULARY# with the same name as the node's title.

#22

alex-and-r - July 25, 2008 - 06:54

@molenick

Thanks in advance for the patch! i think community will appreciate it!

And concerning my #20 comment and your answer to it - thanks for the step-by-step but as for now I figured out where is the problem by myself. It was because of the module weight. I had to go to my phphadmin, to system table and change weight of NAT module to 10. After that everything went smooth.

#23

cray146@drupal.org - July 25, 2008 - 07:06

Subscribing

#24

cray146@drupal.org - July 25, 2008 - 08:30

I made a patch that combines the modifications suggested in #15 and #16.

AttachmentSize
nat-module-155411-24.patch 3.86 KB

#25

white-raven - July 25, 2008 - 15:11

noob apology: I recognize that this should have been a patch, but I don't have CVS on the machine I'm on yet, and I need to review creating patches that contain new files (since there is no nat.views.inc in the 6-dev yet).

Recap: I'm trying to use Drupal 6-Views 2 to achieve the listing behaviour of "same-name node is assigned to its same-name term", without having to file the same-name node under its own term. Basically, if you go to the taxonomy_term view for a NAT term, you should see it's same-name node at the top, followed by all the associated nodes.

I've attached a file that SHOULD use Drupal 6-Views 2 to allow the user to modify the taxonomy_term view to include the same-name NAT node in the list. Haven't written anything to put it at the top of the list yet though. Basically, if you add the defined relationships without checking "require this relationship"--as far as I can tell--it SHOULD include nodes that match the required arguments, --OR-- are linked through the NAT table to the term (namely, the same-name NAT node).

There are issues here though: I don't know whether Views 2 will use --OR-- or --AND-- above... which means if the same-name node isn't linked to its own term (which is what I was trying to avoid requiring), this won't work. Also, I haven't written any code to force the same-name NAT node to the top of the list. Finally, these relationships aren't showing up when I edit a view and I don't know why. I've confirmed Views is seeing the file, but the relationships don't show in the edit view page.

Any help?

P.S. If this approach to this fix is too unrelated to the other code in this thread, let me know and I'll open a separate issue.

AttachmentSize
nat.views.inc.should-be-a-patch 2.29 KB

#26

Rob T - July 25, 2008 - 18:19

I agree that this is a much needed feature, and I appreciate the Drupal 6.x efforts, white-raven.

I was going to use content taxonomy w/ a freetag vocabulary and simply enter the title twice - the second one being in the content taxonomy field. However, utilizing NAT for this would be better, being "auto" and all.

#27

white-raven - July 25, 2008 - 21:00

Fail. All I needed to do was clear Views' cache and my data showed up. That patch doesn't do everything that's needed yet though (the relationships aren't enough alone). I hope to work on it more soon. Anyone else who wants to tinker feel free to post a revision of nat.views.inc.

#28

molenick - July 25, 2008 - 23:12

white-raven, I'm still not clear on what you're trying to achieve - I know that you don't want the term associated with the original node that creates the term but I'm not sure why. Is there some special hurdle you're trying to overcome that precludes this? I'd think that this route gives the most flexibility so that site developers can tie related data together in the manner of their liking.

I think assigning the node it's own term is the most straightforward, flexible way of adding this functionality. Then Views (or Views 2) is not a required component for NAT too. Also, this work is related to 5.x-2.1 and hasn't taken delving into Drupal 6 into consideration.

#29

white-raven - July 28, 2008 - 14:14

@molenick:

I realize this has been work for 5.x; I tried to make it clear that I can move this work to another feature request if the NAT developers think that 6.x development shouldn't be in this thread. I guess, ideologically, associating the same-name node with it's term, to me, sort of "throws it in the bin" with everything that is supposed to point to it, instead of it being "different", "special", or "on top". My reasons for developing in this direction were:

(a) Based on issues I've seen for this module, there has been difficulty finding a bug-free way of associating the same-name node-term pairs; I thought that getting the same-name node in the taxonomy view without having to associate it would "skip over" the bug-fixing for this issue
(b) The ideological issue mentioned above
(c) I was trying to make it so that the same-name node would appear at the top of the term's list--of course, this can be achieved regardless of whether the node is associated with the term.

Shall I create a new issue? Would you recommend developing the "same-name node at top of list" without excluding the "associate same-name node with term" feature? I can see how this would be more useful to developers that aren't using Views, but want to see the same-name node in the list of nodes associated with the same-name term. I agree that tying a feature to Views 2 may not be ideal, but the feature can be seen as optional since all the code would be in Views 2 include files.

I'm happy to hear suggestions from more seasoned Drupal and NAT developers on the best direction for 6.x development.

#30

molenick - July 28, 2008 - 17:25

Ok, I understand now! :)

So basically, you want to create a hierarchy where the original node is a parent above its tagged children. I've use NAT is a similar sort of way but leave the actual taxonomy structure loose and tighten down the information while developing my site. Basically, I create CCK types to represent different satellite nodes orbiting around a core node. There is no hierarchy in the data/taxonomy itself, it is all enforced in the site logic based on taxonomy and CCK type.

I prefer a looser approach as it allows for greater overall flexibility. There are probably a number of ways in which it is preferable to use NAT without forced hierarchy. I do agree with you though, there probably is good use for strict hierarchical (parent-child) relationships.

I know that hierarchical tagging is possible with taxonomy but do not have much experience with it - would it be possible to create a feature of NAT that piggybacks on that to create these strict relationships?

Personally I would not focus so much on the representation (i.e. parent node at the top of the list), rather the underlying data structure - that way once the relationship exist, people can display the data however they wish.

#31

white-raven - July 29, 2008 - 13:56

That's an interesting thought. I'm trying to think of how to make use of hierarchical taxonomy without feeling like I'm "wasting a term" (i.e. having one node be the only thing related to a "parent" term). Although that "waste" I guess wouldn't necessarily be a bad thing. Based on your inspiration, maybe the following feature would be better...

- A Settings option for NAT that says "use a child taxonomy term"
- Setting this option opens up another option that says something like "name of child term (use %parent to insert the parent's name)

Here's an example of usage:
Suppose I have content types "Album" and "Music Review". I set up the Album node type to be NAT nodes under a vocabulary called "Albums", and the Music Review node type can be categorized under Album name NAT terms. Next, I check "use a child taxonomy term", and set the "name of child term" to be "Reviews of %parent"

Now I could have nodes like this:

Album: "Dark Side of the Moon"
Music Review: "Pink Floyd Needs to Lighten Up"
Music Review: "Bring on the Darkness"

And I'd end up with Taxonomy like this (Nodes contain a ^ under their term):

Vocabulary: Albums
-- Term: "Dark Side of the Moon"
^- Album: "Dark Side of the Moon"
---- Term: "Reviews of Dark Side of the Moon"
^--- Music Review: "Pink Floyd Needs to Lighten Up"
^--- Music Review: "Bring on the Darkness"

I think this is what you were thinking, molenick. I can see how this might be more useful and flexible than a hard-coded Views feature that only works when Views is configured to be the "one true way" of viewing taxonomy-classified data.

I'm in the same boat as Molenick with hierarchical Taxonomy terms. I know they exist, but I don't know exactly how easy it is to navigate through the hierarchy. If it is easy, this system would provide quick access to the "parent" NAT node by simply navigating to the parent term's page.

#32

white-raven - July 30, 2008 - 20:10

slight aside: While there's work being done to optimize this module, I have a question and a suggestion about the following query in _nat_sync_associations.

SELECT n.nid FROM {node} n INNER JOIN {node_revisions} nr USING (vid) LEFT JOIN {nat} n1 ON (n.nid = n1.nid AND n1.vid = %d) LEFT JOIN {nat} n2 ON (n.nid = n2.nid AND n2.nid <> n1.nid) WHERE n.type = '%s' AND ISNULL(n1.nid)

Question: What is achieved by the join to node_revisions? Does Drupal track deleted nodes in the node table, an just delete revision when a node is deleted? The reason I guess this is that the inner join would filter out deleted nodes.

Suggestion: The join "nat n2" seems superfluous to me. E.g. (without omitting the node_revisions join):

SELECT n.nid FROM {node} n INNER JOIN {node_revisions} nr USING (vid) LEFT JOIN {nat} n1 ON (n.nid = n1.nid AND n1.vid = %d) WHERE n.type = '%s' AND ISNULL(n1.nid)

As far as I can tell, since the join on "nat n1" is a left join, all nodes will join irrespective of a relationship with the nat table, and then only nodes of type %s that do not have an entry in the NAT table (i.e. n1.nid is NULL) will remain in the final result due to the WHERE clause. Is there something subtle here that I'm missing?

#33

catorghans - August 25, 2008 - 09:22

The #24 patch doesn't seem to work with "sync".

#34

develCuy - October 29, 2008 - 07:36
Status:needs work» reviewed & tested by the community

This patch fixes issue in #33, and I strongly believe this is ready for a commit, can you please include in dev.

Blessings!

AttachmentSize
nat-module-155411-34.patch 4.94 KB

#35

masande - October 29, 2008 - 18:09

patch in #34 works for me at group node creation and deletion. however, my browser times out when i edit the group node. if i then edit the group node, the new nat term is deleted.

i then save the group node again with no problems. editing this iteration of the node shows the nat term is back in the list. however, if i select the nat term again and try to save, the problem repeats itself?

does the above patches only address a group node at the time of creation and not during an update?

has anyone else experienced this problem?

#36

pisco23 - November 2, 2008 - 15:59

subscribe

#37

SamRose - November 10, 2008 - 19:20

Tested patch at http://drupal.org/node/155411#comment-1082354 worked! Terms were added to nodes...

#38

SamRose - November 10, 2008 - 19:45

One small issue that I am having is that when I edit the nodes that terms are attached to, they time out when trying to save them (sometimes a fatal error against taxonomy.module, the process times out)

#39

masande - November 10, 2008 - 23:25

#38 is the same issue i reported in #35.

#40

SamRose - November 11, 2008 - 01:01

Hmmm...a bit of difference in behavior from what you describe, masande, vs. what I experienced. But, they could be related.

In my instance, the terms are saving to the nodes, but when a node is edited and submitted, the submission process times out/takes a huge amount of time, and does not load the saved node upon submission completion, but just gives a WSOD (once with a fatal error). This seems to be what you are describing. But, terms are not being deleted for me. They remain assigned to the node

#41

SamRose - November 11, 2008 - 01:22
Status:reviewed & tested by the community» needs work

...another issue that I noticed, when editing nodes that are term descriptions and attempting to save them, they WSOD as reported in last issue, and top shows that CPU % usage jumps to 99%! Something is of course fundamentally wrong here.

Actually, problem does not seem to be with patch, as the same problem happened when I tried to edit nodes even before the patch was applied.

#42

SamRose - November 11, 2008 - 01:46

masande, further testing shows that indeed my terms are being deleted, too. So, our issue is the same. I upgraded to dev version, and rolled back to older versions of the module, and problem persists

#43

TempusFugit - November 11, 2008 - 11:08
Version:5.x-2.1» 6.x-1.1-beta2

The same issue (terms not linking to nodes) appears in 1.1-beta2 for Drupal 6... Should I open a new issue for that?

#44

develCuy - November 12, 2008 - 23:41

@SamRose, please confirm CPU overload occurs WITHOUT this patch, if so, please file another issue and place the link here.

Blessings!

#45

anantagati - November 13, 2008 - 18:05

I have question.

Is purpose of this patch to assign new created term to new created NAT node?

Because I tested 6.x version and it does what I expect to do, that:
If I create new NAT node, it creates new term which is associated with that node, but node doesn't belong under that term. So By this I can use it for media gallery, where albums are NAT nodes. And photos, videos and other albums are assigned to term which has been created by album and is associated with it. Later I can use Views to show items for specific album (views argument or filter - node nid of album).

So if created term will be assigned as parent for NAT node, this module will not make too much sense for me.

#46

TempusFugit - November 13, 2008 - 19:04

it creates new term which is associated with that node, but node doesn't belong under that term.

So is this a future feature?

#47

anantagati - November 13, 2008 - 20:32

This is current state:

it creates new term which is associated with that node, but node doesn't belong under that term.

This is text from NAT project page:

The NAT module is a helper module used to maintain node-term relationships, i.e. when a node is created, an equivalent taxonomy term is automatically created in any associated vocabularies. This module is a simple but effective way to create node-node relationships via the taxonomy module.

As I understand NAT node supposed to be on same level as associated term, not as child of that term. Assign to node same term which has been created with that node and is associated by NAT, doesn't give a sense for me.

#48

anantagati - November 13, 2008 - 20:41
Priority:critical» normal
Status:needs work» postponed (maintainer needs more info)

The same issue (terms not linking to nodes) appears in 1.1-beta2 for Drupal 6

They are linking to nodes. If you create node, new term is created. That term is associated with that node. If you create other nodes and assign them that term, you can than see them as children of that term, or you can make views with NAT node nid filter and it will show you nodes which belongs to term which is associated to that node.

And if terms link to taxonomy term page, you can change settings in NAT module to replace it with link to NAT node instead of term.

Can you please write more information what is exactly problem?

#49

TempusFugit - November 13, 2008 - 21:01

When a node is created, the relevant term is added to taxonomy. However, the node isn't linked to the term and when a node's terms are listed the NAT-added term isn't among them.

#50

anantagati - November 13, 2008 - 22:25

When a node is created, the relevant term is added to taxonomy. However, the node isn't linked to the term and when a node's terms are listed the NAT-added term isn't among them.

Yes, and this is right behavior.

Example with gallery:
1. You have album node type which with NAT creates terms in 'Album hierarchy' vocabulary
2. When you create album 'Album 1' it creates in 'Album hierarchy' vocabulary term 'Album 1' which is associated with that term through NAT, but created album node is not in that term.
3. When you create another album 'Album 1-1' you can set parent term to 'Album 1'. And also term 'Album 1-1' is created as child of term 'Album 1'
4. When you create another album 'Album 1-2' you can set parent term to 'Album 1'. And also term 'Album 1-2' is created as child of term 'Album 1'
5. You can now create some nodes (photo type, video type, album, ...) and assign them for example term 'Album 1-2'.
6. Now when you make new view with Views 2 module. And use filter or argument 'NAT: Nid' (The node ID of the NAT node) with value of node id of 'Album 1', it will show you nodes which have assigned NAT associated term to node id you provided. In our case you will get 'Album 1-1' and 'Album 1-2'.
7. If you will do same as in previous point (6), but provide node id of 'Album 1-2', you will get list of nodes you made in point 5 and has parent term 'Album 1-2'.

And if you checked 'Make NAT terms in %type node views point to the associated node rather than the taxonomy page.' on settings page, you will see on 'Album 1-2' link to node 'Album 1' instead of link to term 'Album 1'.

So it seems that NAT node is linked to term and everything works as it supposed to work.

#51

develCuy - November 14, 2008 - 01:37

@anantagati, nice explanation, but NAT is not useful only for those cases, current patch provides a feature based on real needs and we don't want to create a forked module for just one feature, right?
I'm using the feature 'Associate an automatically created NAT term with %type parent node?' for a conference site which depends on event.module.
The content type structure is:
Conference (event)
Session
Speech
I need to display a calendar with all sessions and speeches of a particular conference, and the conference. I don't have to create a custom module for that because event.module already provides a filter by taxonomy terms. With this requested feature interface becomes transparent, avoiding to manually associate the automatically created NAT term with the parent for let event.module display the conference in the calendar view.

I'm sure there are another real life cases needing this feature, that is why I encourage you to apply this patch in favor of community.
If you still not agree, please at least provide a hook in order to let us create a plug-in module and avoid hacking.

Thanks in advance for your comprehension.

Blessings!

#52

develCuy - November 14, 2008 - 01:44

[posted by accident]

#53

anantagati - November 14, 2008 - 07:12
Status:postponed (maintainer needs more info)» needs work

I am taking care about Views support for NAT. So lets make a nice patch and let Karthik apply it. Any ideas Karthik?

I went quickly through patch in #34:
- there should be some checking if NAT node type is allowed type for that vocabulary, otherwise we skip setting from Vocabulary edit page.
- use Drupal coding standards (http://drupal.org/coding-standards), for example $vocabulary=taxonomy_get_vocabulary($term['vid']); should be
$vocabulary = taxonomy_get_vocabulary($term['vid']);

please at least provide a hook in order to let us create a plug-in module and avoid hacking.

There is no need to make new hook for this, because you can use hook_nodeapi. You just have to make sure, your module is called after NAT module.
I created new issue #334165: Set $node->nat when new node is created, that NAT module will already fill $node->nat during node insert and you will not need to call nat_get_terms there. Until that issue will be committed, you can just call: $node->nat = nat_get_terms($node->nid); to get NAT associated terms.

#54

anantagati - November 14, 2008 - 05:36
Status:needs work» postponed (maintainer needs more info)

Maybe we can try to find how many uses cases we have for this feature and see if it is better to include it in NAT module or make helper module to enable that.

#55

catorghans - November 14, 2008 - 08:03

I would have used NAT with this feature for the following use case:

A node for a certain content type automatically gets a taxonomy term.
When a node of another content type is edited and this term is selected it will automatically be displayed in a faceted search facet.

If I select the taxonomy term in faceted search I also want the original node to be displayed in the results.

#56

HansBKK - November 15, 2008 - 10:48

+1

I would also like to be able to choose the option "assign auto-created term to original node", as long as it doesn't break existing functionality.

If

  • I am not re-directing the term's link to the same-name node but going to the native taxonomy term display
  • or

  • setting up a View based just on the term (not using the "Nat: nid")

then I want the "NAT node" to show up in the listing

This feature is apparently also required for Panels integration.

PS I'm on D5

#57

TempusFugit - November 16, 2008 - 10:50

Thank you anantagati for your response. I think it would be a nice feature to be added in this module...

#58

anantagati - November 19, 2008 - 19:13

Karthik, can you look on this one?

#59

HansBKK - November 26, 2008 - 19:42

In the meantime, I've found "Taxonomy Node", thinking that it would assign the auto-created same-name node to the original term. I've posted questions on a comparison to their issue queue:

http://drupal.org/node/335496

Edit: apparently does not, and also no Views integration

#60

Summit - November 26, 2008 - 15:41

Subscribing, greetings, Martijn

#61

Ruslan@SkiffleMedia - January 4, 2009 - 13:44

Subscribing

#62

msn - January 27, 2009 - 01:53

Subscribing

#63

jalama - February 5, 2009 - 21:01

Though I'm a little confused if the patch i supposed to fix the original topic of this thread the

patch in #34 hangs for me
Drupal 6.9

#64

anantagati - February 15, 2009 - 03:43
Version:6.x-1.1-beta2» 6.x-1.x-dev
Status:postponed (maintainer needs more info)» needs work

Is there any progress?

#65

Zen - February 17, 2009 - 07:12

I tested the D5 patch.

  • When I create a NAT node, it becomes a child of "itself" cleanly enough. However, I cannot view the associated term on the taxonomy admin page.
  • When I try to view the term's page, I get a WSOD and Drupal times out.

If somebody can rework and reroll for D6, it'll be great.

Cheers,
-K

#66

Oghnia - February 25, 2009 - 15:14

it doesn't look like this one has been solved yet

#67

bohz - May 8, 2009 - 07:48

[subscribing]

#68

Flying Drupalist - May 23, 2009 - 18:25

Subscribe

#69

hotspoons - June 3, 2009 - 00:09

I ported the patch in comment 34 (here) to drupal 6 against the latest dev version. It appears to work as advertised. Anyone want to test it out?

*edit*

I found that the patch works fine when creating a node, but it loses the association upon editing the node, mainly because elsewhere in the module (its in hook_form_alter) the associated term with the node is unset from the list of terms when editing a node by design. Perhaps I'll try adding a case to check if the content type has automatic association, and if so, skip the block that unsets the taxonomy term associated with it. I'll try and get something up later tonight. Thanks,

-Rich

AttachmentSize
df5675543d3a.diff 6.58 KB

#70

hotspoons - June 3, 2009 - 02:54

I updated the patch to conditionally *not* remove the NAT term from the taxonomy form element in the case that automatic association is turned on for the current content type; this allows the term to remain associated after editing, or you can opt to unassociate it, if you wish.

Then I ran into a bigger problem - the WSOD/script timeout others experienced above. The script was timing out on the taxonomy_get_parents() function in taxonomy.module. I found this was called from taxonomy_del_term(), which is called from taxonomy_save_term() (probably, since this is one of the only entry points to the function anywhere I could find), which is called from _nat_update_terms() in the nat module. There has to be some sort of bad bit of data being passed into the ['parent'] element of the "form" data passed to taxonomy_save_term(). Here's the node object I was trying to save at the time:

stdClass::__set_state(array(
   'nid' => '398',
   'vid' => '398',
   'uid' => '1',
   'created' => 1243992318,
   'type' => 'schools',
   'language' => '',
   'changed' => 1243992720,
   'title' => 'ACCE High School',
   'teaser_include' => 1,
   'body' => '',
   'format' => '1',
   'revision' => 0,
   'name' => 'admin',
   'date' => '2009-06-02 21:25:18 -0400',
   'status' => 1,
   'promote' => 1,
   'sticky' => 0,
   'op' => 'Save',
   'submit' => 'Save',
   'preview' => 'Preview',
   'delete' => 'Delete',
   'form_build_id' => 'form-113a06c24203ca50a1cef3adfd42c2dd',
   'form_token' => '7ccb28629954d4158e68c0cfd133a437',
   'form_id' => 'schools_node_form',
   'comment' => '2',
   'menu' =>
  array (
    'mlid' => 0,
    'module' => 'menu',
    'hidden' => 0,
    'has_children' => 0,
    'customized' => 0,
    'options' =>
    array (
    ),
    'expanded' => 0,
    'parent_depth_limit' => 8,
    'link_title' => '',
    'parent' => 'primary-links:0',
    'weight' => '0',
    'plid' => '0',
    'menu_name' => 'primary-links',
  ),
   'path' => 'content/acce-high-school',
   'pid' => '65',
   'pathauto_perform_alias' => 1,
   'old_alias' => 'content/acce-high-school',
   'taxonomy' =>
  array (
    4 =>
    array (
      38 => '38',
    ),
  ),
   'upload' => '',
   'attach' => 'Attach',
   'field_location' =>
  array (
    0 =>
    array (
      'lid' => false,
      'name' => '',
      'street' => '',
      'additional' => '',
      'city' => '',
      'province' => '',
      'postal_code' => '',
      'country' => 'us',
      'locpick' => false,
      'latitude' => 0,
      'longitude' => 0,
      'source' => 0,
      'is_primary' => 0,
      'delete_location' => false,
      'phone' => '',
      'location_settings' =>
      array (
        'form' =>
        array (
          'fields' =>
          array (
            'lid' =>
            array (
              'default' => false,
            ),
            'name' =>
            array (
              'default' => '',
              'collect' => 1,
              'weight' => 2,
            ),
            'street' =>
            array (
              'default' => '',
              'collect' => 1,
              'weight' => 4,
            ),
            'additional' =>
            array (
              'default' => '',
              'collect' => 1,
              'weight' => 6,
            ),
            'city' =>
            array (
              'default' => '',
              'collect' => 0,
              'weight' => 8,
            ),
            'province' =>
            array (
              'default' => '',
              'collect' => 0,
              'weight' => 10,
            ),
            'postal_code' =>
            array (
              'default' => '',
              'collect' => 0,
              'weight' => 12,
            ),
            'country' =>
            array (
              'default' => 'us',
              'collect' => 1,
              'weight' => 14,
            ),
            'locpick' =>
            array (
              'default' => false,
              'collect' => 1,
              'weight' => 20,
              'nodiff' => true,
            ),
            'latitude' =>
            array (
              'default' => 0,
            ),
            'longitude' =>
            array (
              'default' => 0,
            ),
            'source' =>
            array (
              'default' => 0,
            ),
            'is_primary' =>
            array (
              'default' => 0,
            ),
            'delete_location' =>
            array (
              'default' => false,
              'nodiff' => true,
            ),
            'phone' =>
            array (
              'default' => '',
              'collect' => 0,
              'weight' => 25,
            ),
          ),
        ),
      ),
    ),
  ),
   'field_picture' =>
  array (
    0 => NULL,
  ),
   'field_school_type' =>
  array (
    0 =>
    array (
      'value' => 'high',
    ),
  ),
   'teaser' => '',
   'validated' => true,
   'is_new' => false,
   'timestamp' => 1243992720,
))

And the $edit array that was passed to $taxonomy_save_term() from _nat_update_terms():

array (
  'name' => 'ACCE High School',
  'description' => '',
  'tid' => '38',
  'vid' => '4',
  'weight' => '0',
  'parent' =>
  array (
    38 => '38',
  ),
  'relations' =>
  array (
  ),
  'synonyms' => '',
)

The auto-created term had an ID of 38 and a VID of 4.

I would take a guess that it has something to do with the parent being set as itself, causing an endless loop, but I didn't read into the taxonomy module enough to know exactly what was happening.

To temporarily fix it, I removed the parent key from the $edit array in the patch from _nat_update_terms(), and it works fine on a flat (non-hierarchical) vocabulary, but I don't know what effect that will have on a tree-type vocabulary.

Maybe someone more familiar with the effects of removing the 'parent' attribute could elaborate more, but as far as I can tell, unless the hierarchy was updated from the node edit form (I don't see how), the drupal_write_record() function that actually stores the data shouldn't overwrite the current parent data associated with the TID. Ideas? Thanks,

-Rich

AttachmentSize
16ff252e5d3c.diff 9.47 KB

#71

alexm77 - June 10, 2009 - 13:36

subscribe

#72

kierduros - June 11, 2009 - 19:01

Would definitely love to be able to have the node creating the term auto-associated with the term it creates. (Or at least a way to avoid a manually added link to that term via the normal taxonomy method not fall apart when the node gets edited.)

#73

asb - June 21, 2009 - 01:07

subscribing

#74

aded - June 29, 2009 - 08:41

subscribing

#75

mattiasj - July 8, 2009 - 07:19

This would be great functionality, for example it could be used to make views sortable from taxonomy weight and then use taxonomy for clients to order the nodes.

#76

autopoietic - August 26, 2009 - 14:54

subscribing

#77

NikLP - September 15, 2009 - 17:05

The logical thing, to me, seems to be to add a form field (radio) which reads like this:

"(For hierarchical vocabularies,) when assigning a term to a node:

- assign the selected term to the node (term is 'parent' of the node, new unassigned child term is created also)
- assign the newly created term to the node (new term is created as child of the selected term - node is directly related to the new term via a one-to-one relationship)"

Or something like that. Then we just have to switch on that based on what the setting is and save the node relationships accordingly.

Edit: probably also need to cater for this: If the "Make NAT terms in *type* node views point to the associated node rather than the taxonomy page." option is selected and we're on a node page that relates to one that's configured with that option, we need to _alter out the link, otherwise it will be linking to itself! :)

#78

develCuy - September 15, 2009 - 18:53

+1

#79

NikLP - September 15, 2009 - 22:34

Actually, that applies in some cases to non-hierarchical vocabs too...

#80

lyricnz - September 17, 2009 - 14:55

NikLP etc - He's a quick patch that applies all the nat-module terms to the node itself. It doesn't have any UI, and requires that you (manually) set the module weight of "nat" lower than "taxonomy" (say to -1). Let me know if this is (the start of) what you're looking for.

[Edit: patch is against NAT 6.x-1.1-beta3]

AttachmentSize
nat.apply-nat-terms.patch 1.36 KB

#81

NikLP - September 16, 2009 - 16:11

Si - In the patch, you add three lines for _nat_fixup_term_node($node); when actually moving it outside the case statements will do, I think. FYI.

I know you probably just C&P'd that in there - just noting it down.

#82

lyricnz - September 16, 2009 - 22:16

NikLP: The code is fine - you should only fixup the node terms when they are updated ($op = insert/update/delete), not the many other times hook_nodeapi is called.

#83

lyricnz - September 17, 2009 - 12:20

Here's another patch (for 6.x-1.x-dev) that adds some UI for configuring this.

AttachmentSize
nat.attach-term.patch 3.99 KB

#84

NikLP - September 17, 2009 - 17:11

Other stuff for consideration....

Maybe change text: "Make NAT terms in property node views point to the associated node rather than the taxonomy page."
to
"Make NAT term links in property node views point to the associated node rather than the taxonomy term page."

Maybe change text: "Attach the newly created term to the property node"
to
"Assign the newly created term to the property node (otherwise the term selected at node add time will be assigned)", WDYT?

For the option: "Make NAT terms in property node views point to the associated node rather than the taxonomy page."...

I'm not sure this makes complete sense. This says, "on property pages, show the taxo link as a node link". This effectively means that the node will forever be linking to itself on the same page, which is crazy.

It would make sense to me that anywhere terms from this *vocabulary* were displayed, that they linked to the nodes - is that the case? Otherwise, there should probably be another option "remove link when it points to it's own node". I.e., if we're showing a property node, we don't need to link to it. If we're showing a profile node, where the also profile is categorised with this vocab, THEN we should definitely be linking to the property node.

*Edit: You know what... I'm starting to think that scrapping this and starting again might be an idea, for my use case at least... "taxonomy_nodemap" namespace is looking ever more attractive.

 
 

Drupal is a registered trademark of Dries Buytaert.