Posted by AlexisWilke on June 13, 2009 at 8:16pm
| Project: | Rules |
| Version: | 7.x-2.x-dev |
| Component: | Rules Engine |
| Category: | feature request |
| Priority: | normal |
| Assigned: | AlexisWilke |
| Status: | needs work |
Issue Summary
Hi guys,
This function will assign a term as the parent of another term. You first need to load the two term or add a term and load another. Name one term Child and the other Parent, then use this taxonomy patch to assign one term as the parent of the other.
Thank you.
Alexis Wilke
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| rules-6.x-parent_term.patch | 1.58 KB | Idle | FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch rules-6.x-parent_term.patch. | View details | Re-test |
Comments
#1
We actually need to delete the hierarchy entry with the given TID and Parent = 0.
New patch attached.
Thank you.
Alexis
#2
Hm, I don't like fiddling around in foreign database tables. This should be done by API if possible. --> http://api.drupal.org/api/function/taxonomy_save_term/6
Ideally we should make the taxonomy_term data object savable, as noted in #456328: Taxonomy actions: Add/Delete term
#3
#4
Was this ever implemented? Does anyone know how to assign a parent term to a newly created taxonomy term in rules?
Specifically what I need:
Action: 'after saving new term'
Do: Assign child term to newly created term.
#5
I have temporarily implemented this patch... so far it is working as designed. I will report any problems.
#6
@fago,
Btw, there is no taxonomy functions in taxnomy.module that would look like helper functions to do this work. It works for me and tngcas now. Maybe you want to re-review this? If you find a function that tweaks the hierarchy that doesn't take a $form_values as input, I'll be happy to look into it.
Thank you.
Alexis
#7
The last submitted patch, rules-6.x-parent_term.patch, failed testing.
#8
New version against 6.x-1.4 which I would imagine is really close to 6.x-1.x-dev.
Let's see if the patch applies to the lastest checkotu of the code-base (see http://qa.drupal.org/pifr/test/123584 )
#9
hm, what about making use of taxonomy_term_save() by casting the term object to an array before?
Anyway, in the meantime rules2 is in dev so we need to make sure new features work there, before we can backport them to d6.
For d7, I think we should just make sure we can manipulate term:parent accordingly via the generic list actions.
#10
any news about this implementation?
it will help a lot with managing sections of magazines that are organized by taxonomy.
thanks for all your work :)
#edit: i used the patch and it works in drupal 6.20
thanks a lot, i had a night mare with taxonomy and i discovered rules but i was not able to do this.
it would be nice to have an action for deleting to apply when a term is deleted.
now i go to see if coping your patch i can do the same with related terms.
my need: when i create a magazine, i need to create the sections and relate to the sections of previous magazines.
thanks thanks :)
if i am suscesful with related terms, i put the code here :)
#11
it worked!!
thanks for what i learn from both of you, AlexisWilke and fago :)
i am sure you will implement it much better than me but for my night mare for the moment it is enough and it is not complicated for an update on your module on the site that i am building.
I put the code just under the AlexisWilke lines.
please, take into acount that i am not an expert :)
/**
* to have related term
*/
$info['rules_action_taxonomy_assign_related_term'] = array(
'label' => t('Assign a related term to a term'),
'arguments' => array(
'taxonomy_term_related_1' => array(
'type' => 'taxonomy_term',
'label' => t('Related term 1'),
),
'taxonomy_term_related_2' => array(
'type' => 'taxonomy_term',
'label' => t('Related term 2'),
),
),
'help' => t('Use two terms and make them related. The terms must be previously loaded or added.'),
'module' => 'Taxonomy',
);
/**
* finish related terms
*/
/** Here goes under the second piece of AlexisWilke patch
* Action: Assign a term
*/
function rules_action_taxonomy_assign_related_term($taxonomy_term_related_1, $taxonomy_term_related_2, $settings) {
$sql = "INSERT INTO {term_relation} (tid1, tid2) VALUES (%d, %d)";
db_query($sql, $taxonomy_term_related_1->tid, $taxonomy_term_related_2->tid);
return array('taxonomy_term_related_2' => $taxonomy_term_related_2);
}
/**
* ends the second piece
*/
#12
hello again
i am very excited this morning playing with rules.
sure that i am not doing it as good as if i was using it for a while but i am very happy :)
i tell here one idea, just in case AlexisWilke wants to take it into account and implement it... :)
or anybody in the community...
my case is that i create a magazine and when it is created, i create terms that refer to the sections.
then i assign the parent to each term.
so i do a very repetitive rules.
load vocabulary, add term, load term (which will be the parent) and assing the parent.
if in AlexisWilke code, i could assing vocabulary->term, since i have loaded the vocabulary already, then i wouldnt need to load a term each time for it to be assigned to the child.
i wish i had the knowledge to do it and add it here... but at the moment no.
it would be a pleasure to me to be able to return a bit of what i got from you :)
thanks and i will have an eye on rules for future sites: its great!!!
#13
candelas,
Somehow, pretty much all my patches have been refused (not applied) by the author of rules. So I don't feel compelled in helping more for having to apply perfectly working patches forever.
Thank you.
Alexis