Hi guys,
There is a small patch to add two conditions on terms. Although one of them (i.e. comparing two terms together) may not really be achievable at this time, it is available right now!
The other condition is to test the existence of a term. Returns true if a term exists. It can be used to avoid creating the term multiple times, for instance. Or to allow/forbid something as I was thinking it could be useful to have a way to deny access to a node from the Rules module. 8-) But I'm not too sure there is a hook available for that purpose...
Thank you.
Alexis Wilke
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | rules-6.x-term_exists.patch | 3.78 KB | AlexisWilke |
| #39 | rules-6.x-all_changes.patch | 13.28 KB | AlexisWilke |
| #28 | rules_term_condition_ui.png | 63.83 KB | rickvug |
| #23 | rules_490898_3.patch | 3.78 KB | Ravi.J |
| #21 | rules_490898_2.patch | 4.19 KB | Ravi.J |
Comments
Comment #1
fagoYep, some conditions would definitely make sense. Some points:
1. There is no need for this code comment:
+ // I suppose this cannot be achieved yet...
+ // It could be used to compare the parent of two distinct terms...
2. Code style:
Please keep array definitons in 1 line as long as the aren't longer than 80chars,
e.g. I think
+ 'term1' => array(
+ 'type' => 'taxonomy_term',
+ 'label' => t('Term 1')
+ ),
could be one line.
@rules_condition_term_exists
I think this should also take the vocabulary as argument. The problem with that is only, that as of now arguments may not be optional (again rules 2..). However I think usually the user wants to check in an existing vocabulary nevertheless, as there is no possibility to use a term from one vocabulary in others, thus I think it's ok to enforce a vocabulary argument.
This should also help to simplify the condition's code itself. :)
Comment #2
jbeall commentedSubscribing, I would like to be able to define a condition that checks to see if the content has been tagged with a term that is in a specific set of terms. For instance, to say "this condition is met if the content has been tagged with the terms blue, yellow, or green in the 'colors' vocabulary."
-Josh
Comment #3
AlexisWilke commentedfago,
Should the user load the vocabulary in a previous rule? Or should it be hard coded? (and see the problem of variable naming I submitted...#501336: Help with rule sets configuration: variable already exists)
Josh,
That should be doable since the comma is accepted as a separator in the taxonomy tag entry we can assume no tag would include a comma (and if it does, fix it.)
Thank you.
Alexis
Comment #4
fago>Should the user load the vocabulary in a previous rule?
Yes!
Comment #5
SlayJay commentedIs there a way for me to alter this patch to let me have a condition on if a node has a certain term?
Using the above example, I'd like to fire off an action if a new node has the term "yellow"
Comment #6
AlexisWilke commentedYes, that function offers that functionality:
rules_condition_term_exists()
I have not been using Rules for a while so I do not know whether this patch is still applying and works. But from what I've seen, there weren't that many changes so if you're using 1.x you should be good to go.
Thank you.
Alexis
Comment #7
leon85321 commented@endorn have you come out a solution for that?? I am also trying to use the rule for if a node has a term "whatever" and do some sending email actions.
Thanks.
Comment #8
aleighs commentedWhile the UI is a bit confusing with the drop-down or VID and then typing the term name, the patch is actually functioning well for me. Thanks.
Also, this issue is a duplicate of http://drupal.org/node/343403
Comment #9
AlexisWilke commentedaleighs,
If you fix the patch as asked by fago in #1, maybe it will be checked in. At times I wonder why such demanding authors don't do that work themselves. 2 lines to edit... A big killer. 8-)
Thank you.
Alexis
Comment #10
traviscarden commentedSubscribing.
Comment #11
TS79 commentedthe current patch
Comment #12
melchoir55 commentedI'm excited to test this functionality.
Does this patch apply to the 6.13 rules.module found at rules\rules\rules.module? The hunks fail through cygwin when I attempt to apply...
Edit:
nevermind found the file path declared in the patch
Comment #13
AlexisWilke commentedHow come you changed the $Id: $ ? And note that a proper $Id: $ include a colon and a space, although I think the CVS in Drupal is smart enough to understand the $Id$ it is not conventional.
Thank you.
Alexis
Comment #14
TS79 commentedHi,
i add a patch V3 with the following extension:
- an additional condition, which checks the existence of a term on a given node object (e.g. after node events like "update node" useful)
- some improved commentation of the functions (old comments have been still from "user"-rules-conditions)
- elimination of the next potential killer issue "$Id$" ;)
Both patches have been created on version "6.x-1.2" of rules module.
Sry foor the late posting, I was not able to finish the work yesterday....
Comment #15
TS79 commentedComment #16
TS79 commentedComment #18
rickvug commentedsub.
Comment #19
Ravi.J commentedCleaned patch committing again
Comment #20
klausiUgly formatting, see http://drupal.org/node/1354
we use "@todo" to mark future work
Comments start with a capital letter and end with a dot.
Powered by Dreditor.
Comment #21
Ravi.J commentedCleaned up and re-attached.
Condition to compare vocabularies dropped from the patch
Comment #23
Ravi.J commentedCleaned up and did fresh patch
Comment #24
Ravi.J commentedComment #25
Ravi.J commented@klausi , I have redone the patch, Cleaned up the parts that you had pointed in previous review.
Comment #26
hagner commentedPerfect! Works fine for me!
Comment #27
AlexisWilke commentedThanks Ravi for the extra work. 8-)
Comment #28
rickvug commentedI think there are a number of areas needing work here. The first is that the user interface is strange, specifically when selecting a vocabulary. Why is the option to select a vocabulary by vid present? The select box should be sufficient.
Related, I'm wondering if matching on term name is a good idea. What about if the term is retitled? Selecting a term id would be more inline with how taxonomy works. Perhaps autocomplete would work best here? This would require more complexity (multistep) in the form since autocomplete would depend on the vocabulary being set.
Another major issue in the last patch is that the condition only checks if the term itself exists, which isn't very useful. Instead, the condition should accept node as the argument so one can check if that term is attached to the given node (or any other node that is loaded).
Finally, I see the following error when the condition is configured (E_STRICT report with D6 dev):
Comment #29
AlexisWilke commentedrickvug,
The very point of this patch is to match items by name. If you do not like it, you may want to work on your own version and provide another patch. It is very useful to know whether a term exists. It's not because you don't need it that it's not useful.
If I recall properly, the vocabulary selection is the same here as it is in other places and it was required to get the list of terms.
Thank you.
Alexis Wilke
Comment #30
rickvug commentedAlexis - Sorry if the patch review came across harshly. Perhaps two taxonomy conditions should be developed: one to check if a term with a specific title exists, another to check if a specific term is attached to a node. As for the configuration forms, I'll take a look at other taxonomy rules forms. If it is consistent that may also be another issue.
Comment #31
Sepero commented#19: rules_490898.patch queued for re-testing.
Comment #32
mstrelan commentedBefore reading #28 I tested the patch and was going to write the exact same things. Also I don't think "term exists" is the best label. And finally I think there needs to be a way to allow multiple terms, which rickvug suggests should be term ids. Checkboxes would work well.
Comment #33
AlexisWilke commentedmstrelan,
No way. With a taxonomy that has 200,000 terms, checkboxes won't work at all. Now having multiple auto-complete and a way to add more is a good thing but not having anything to check terms is much worse. So blocking the existing patch to add yet another feature is not smart.
Thank you.
Alexis
Comment #34
abdelaziz10 commentedComment #35
fastcat.org commentedReally wishing for the "term set on node" here
Comment #36
bjalford commentedany progress with getting this committed?
Comment #37
aerodub commented#23 patch does not seem to work for me, condition returns always FALSE whether a term exists in vocabulary or not.
Comment #38
Ravi.J commentedI am going to take another stab at this , hopefully will be able to get it to RTBC ..
Comment #39
AlexisWilke commentedThere is a patch with all my changes as of 1.4. This includes everything I've done, not just what is supposed to be part of this issue... but maybe one other person will enjoy the features offered.
The patch in #23 was very similar to mine so I don't right now see why it wouldn't work... More later if I find something's wrong.
Thank you.
Alexis
Comment #40
AlexisWilke commentedOkay, there is a problem with the vocabulary ($vid) which uses the wrong name in the settings array.
There is a fix to patch found in #23 for that problem. However, it does not explain the problem reported in #37.
Thank you.
Alexis Wilke
Comment #41
AlexisWilke commented@aerodub,
Are you testing with the NAME of a term? (opposed to its identifier which is what you are supposed to use)
Thank you.
Alexis
Comment #42
AlexisWilke commentedfixing the title
Comment #43
westie commented+1 subscribing
Comment #44
cato commentedLooking for just this functionality or I'm stuck writing custom php code conditions. Status update? Anything I can do to help out?
//Christopher Cato
Comment #45
cato commentedFor anyone wanting this functionality, here is a little how to..
My usecase is that on creation of a node of the type Customer I want rules to create a taxonomy term in a specific vocabulary (customers) from the node title of the created content (node title = customer name). If it exists, rules should do nothing. For this we need a conditional.
Basically it looks like this:
The php code to check if the term exists is
Comment #46
AlexisWilke commentedcato,
Did you try applying patch in #40 to see whether you could do what you're trying to do?
Thank you.
Alexis
Comment #47
cato commented@AlexisWilke
No, I didn't try the patch - I generally avoid patching modules or core as it can make maintenance hard if , for instance, future releases provide functions that is not compatible with the patch.
Will this functionality be in the next release? It wasn't my intention to hijack this issue with my custom code by the way, sorry!
Thanks // Christopher
Comment #48
AlexisWilke commentedWell... I guess you have a point since I opened this on June 13, 2009 and the author (fago) did not yet apply the patch to the Rules code... 8-)
So you have two solutions: you keep Rules the way it is or you use the patch here and you don't have to write the code. Now, writing your own solution in a separate module may be a good solution too.
Thank you.
Alexis Wilke
Comment #49
Katrina B commentedI am subscribing to this thread, as I need the ability to test for the existence of a term as a condition: If a node has a particular term attached to it, then do this (whatever "this" might be).
Where I work, I don't have the ability to patch modules (more accurately, I'm not allowed to), so I'm hoping this feature will be included in Rules soon.
Comment #50
AlexisWilke commentedKatrina B,
You may want to test with the patch in #40 and see whether it works for you. If so, then mark the status as RTBC.
Thank you.
Alexis Wilke
Comment #51
Katrina B commentedUnfortunately, as I noted earlier, I cannot patch modules at my job; I don't have access to Terminal (which is what I would need to use on the Macintosh in order to apply a patch), so I don't have the ability to test the patch. I'll have to wait until the feature has been implemented in Rules.
Comment #52
asb commentedHoly cow, what is wrong with issues like this? Started on June 13, 2009 - more than two years ago; several patches have been provided, and finally a patch has passed Simpletest, and nobody made founded objections, not even about the position of dots in comments. Still this code is not even in rules-6.x-1.x-dev. I don't get it.
The patch from #40 applies cleanly against rules-6.x-1.4:
Also, it works exactly as advertised. I would even use it if it had no closing dot in the comments.
My use case: When creating a new node of a certain type, some data is pulled from an external source and made available as tokens. With Rules, I'm populating several vocabularies with these tokens. The vanilla rules-6.x-1.4 is totally useless in this scenario as it only allows to unconditionally enter a new term; the result are numerous duplicates. #40 solves this problem as it allows to compare a token with the exisiting terms. Works perfectly for me!
Please committ!
Comment #53
fagoLooks like not enough people were interested into that... Here a review:
Condition Taxonomy? That does not tell me anything. Should end with a trailing point.
Why should the vocabulary be loaded? Anyway, I don't think we need that by-id stuff. Let's just go with a select for vocabularies.
Needs to improved. I cannot remember something I don't know yet.
Comment #54
mitchell commentedAnyone have time to help get this committed?
Comment #55
funana commentedIs there a way to do this in Drupal 7?
Thanks :)
Comment #56
tr commentedDrupal 6 end-of-life was more than two years ago - there will be no new feature in D6 Rules, and D6 Rules is no longer supported.
That said, this could go into Rules for D7 or D8 if someone is willing to contribute code or fund the development of this feature.