Is there anyway to use taxonomy terms to cause an action to take place?

My goal is to have an individual notified when a forum topic has been created within a specific forum or a comment has been placed within this specific forum.

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Category: support » feature

hnm, there are no conditions yet. I think conditions like "Content has term assigned" would make sense. patches welcome.. ;)

Dinis’s picture

I'm trying to do this too, any idea what the PHP would look like in the condition?

EmanueleQuinto’s picture

FileSize
2.01 KB

This patch is a plain-vanilla implementation of taxonomy conditions .

It allows you to enter a comma separated list of term (numeric tid) to check against node taxonomy terms.

It doesn't have any form validation, vocabulary selection... but it seems to work (almost on our staging server).

EmanueleQuinto’s picture

Status: Active » Needs work
Dinis’s picture

This looks perfect, I'll pop it onto dev tomorrow and test it :)

amitaibu’s picture

+ $info['taxonomy_rules_has_tid'] = array(

I except this function to return a bolean - if content has a term or not.
You should probably add another function 'taxonomy_rules_condition_content_has_specific_term'. That condition can take a 'taxonomy_term' argument, and will check a content has that specific term.

fago’s picture

Also be sure to obey the drupal coding standards and remove any codelines commented out.

fearlsgroove’s picture

FileSize
11.77 KB

This patch includes has term and has term in vocab conditions, along with some other stuff in like creating user roles. It also adds text fields supporting input processing for all vocab related functions and some other updates.

This definitely needs cleaning and work, and possibly even to be split amonst several patches since it goes beyond the scope of this issue. Think of this more like a brain dump. Also patch was created as a diff from my svn repo, which imported and tracks the 1.x-dev cvs repo, but had #456328: Taxonomy actions: Add/Delete term committed already, so it'll probably hunk a bit. When I have time to come back to this (a week or so) I'll clean up and split it out into separate patches if no one else has picked it up.

Anonymous’s picture

Hi all,

This patch looks promising, what would I need to change to apply EmanueleQuinto's - May 11, 2009 - 07:34 patch for the taxonomy terms?

Edit:

Done, very nice work.

mitchell’s picture

Status: Needs work » Postponed

Not trying to stop development here, but since this depends on #456328: Taxonomy actions: Add/Delete term, marking as postponed.

jbeall’s picture

Subscribing, 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

jbeall’s picture

Could you elaborate why this depends on #456328: Taxonomy actions: Add/Delete term? That is the bug for modifying (add/delete) terms, but this issue is for inspecting the value of a term. It doesn't seem like we'd need to have a rule that adds or deletes terms before we would be able to inspect the value of terms on the node... ???

jvieille’s picture

I would need this feature.
When could it be committed?

klausi’s picture

Status: Postponed » Needs review

Setting back to needs work.

klausi’s picture

Status: Needs review » Needs work

whoops.

TravisCarden’s picture

+subscribe

rhodebump’s picture

+subscribe

catorghans’s picture

This request makes sense to me. Or I should replace the taxonomy term with a cck field.

jvieille’s picture

Any progress on that?
#8 from fearlsgroove was very exciting.
Starting by our deadly missing term condition?

fago’s picture

Category: feature » task

Patch still needs a clean-up.

my-family’s picture

Nice idea, I would appreciate this feature too. Subscribing.

Bilmar’s picture

subscribing

Agileware’s picture

Subscribing. But working around this one for now.

robby.smith’s picture

+1 subscribing

Sylvain_G’s picture

+1 subscribing

mitchell’s picture

Category: task » feature
Mindy’s picture

This would be really powerful. I'm looking forward to seeing it happen. Is this a duplicate of http://drupal.org/node/490898?

kloewer’s picture

Applyed Patch #8 and can assign Rule to "Content has term in vocab assigned"

But get error Message:

Unable to find "condition" of name "taxonomy_rules_has_vocab" with the label "Content has term in vocab assigned". Perhaps the according module has been deactivated.

SlayJay’s picture

Any update on this? This is a deal breaker for my website that I assumed wouldn't be an issue.

I need a way to "trigger" an action based on when someone posts content into a specific forum. Since Advanced Forums uses taxonomy to decide what forum content is in, I've hit a wall without this.

The patch in #8 is producing the same error from post #28 for me.

Does anyone have a work around, or another way of handling this with other modules?

/begs

my-family’s picture

#29: For the time being, I use Content Taxonomy fields for this purpose. However, (I don't know why) it works for me only if I specify the condition with PHP (execute custom PHP code), e.g.: return $node->field_section_taxonomy[0]['value']=='5'; (I don't know if Content Taxonomy could be used in Advanced Forum...)

... Anyway, I would appreciate "built-in" conditions for taxonomy terms in Rules very much.

nassimo3’s picture

Subscribe...

rconstantine’s picture

A hack I use for content_taxonomy is this:

function _content_rules_field_has_value($node_value, $value, $field) {
  if (($field['type'] == 'content_taxonomy') || ($field['type'] == 'text' && $field['widget']['type'] == 'optionwidgets_buttons')) {
    $the_array = array_intersect($node_value, $value);
    if (!empty($the_array)) {
      return TRUE;
    }
  }
  else {
    if (count($value) != count($node_value)) {
      return FALSE;
    }
    // Loop over multiple fields
    foreach ($value as $delta => $sub_value) {
      // Check if all properties of the value are there in the node value too
      if (count(array_diff_assoc($sub_value, $node_value[$delta])) != 0) {
        return FALSE;
      }
    }
  }
  return TRUE;
}

You can see I also use it for optionwidgets' checkboxes where I want the rule to fire if at least one is checked. Note that for taxonomy, this also fires if at least one term is present. If you want ALL terms present, or in the case of checkboxes, ALL items selected, then I'd say we need a button added to the admin of the rule creation to select between ONE or ALL, then handle that here. But I think in most cases, we want to allow more than one value in these fields, but react to one of them as I have done here.

SlayJay’s picture

#32

Your patch seems to work fine (as in, the condition shows up and appears to be working) but I'm having an issue populating the content taxonomy field with the current node's taxonomy.

for example:

Every forum topic content has a taxonomy term of it's parent forum container. If a forum topic is under the "Applications" parent, then it has a taxonomy of "Applications" from the "forum" vocab.

I assumed that content taxonomy would be a CCK field that showed all of the nodes current taxonomy, so setting a rule of "If content_taxonomy field == "Applications" then do something" would be simple... but it seems thats not how content_taxonomy functions.

Any suggestions? Basically I'm trying to get events to fire after forum posts in certain forums are made.

SlayJay’s picture

I was able to get the effect I needed (trigger if content has one specific taxonomy term) by using the following code as a custom php code trigger. I can confirm this works with advanced forums on drupal 6.


//####  Define What Taxonomy Term to Search For
$term_text = "Applications";
//#############################
$terms = taxonomy_node_get_terms($node);
$tid = taxonomy_get_term_by_name($term_text);
$tid = $tid[0];
$tid = $tid->tid;
if (isset($terms[$tid])) {
	return true;
} else {
	return false;
}

someone more familiar with rules may be able to make a patch out of this. Hope it helps someone!

EmanueleQuinto’s picture

The attached patch is simply an updated version of #3.

Minimal UI and minimal code: you must enter a comma separated list of (numeric) tids.

I didn't implement the solution proposed in #8 because UI isn't IMHO clear: you can use the dropdown (and select only one term) OR the textarea (and put multiple tids). I guess would be better to create a checkboxes fieldset for this or implement an autocomplete (like tags) so would be possible to use term name (much fancier for users).

leon85321’s picture

hi, thx for the patch, any progress on select list/checkbox instead of inputing the term id?

YK85’s picture

Status: Needs work » Needs review

needs review for #35?

Status: Needs review » Needs work

The last submitted patch, taxonomy.rules_.inc_terms_conditions_6.x-1.2.patch, failed testing.

aleighs’s picture

I am not able to get the patch in #35 to work.

I can confirm that the rule is functioning without the "taxonomy condition" and that something in its place like "and sticky" is working. Here's the scenario I tested it in. When content is saved > if content type is "X" > AND has term id of "123" then modify node terms.

However, it is working on the second save of the node when I have the argument configuration set to "unchanged content", but not on the first save of the node.

aleighs’s picture

This issue is a duplicate of http://drupal.org/node/49089. The patch there is working for me.

klausi’s picture

Status: Needs work » Closed (duplicate)

Marking this as duplicate of #490898: Condition: does term exist?

Sepero’s picture

Status: Closed (duplicate) » Needs review

#8: rules-many-additions.patch queued for re-testing.

klausi’s picture

Status: Needs review » Closed (duplicate)
fastcat.org’s picture

Unless I'm missing something big, this and http://drupal.org/node/49089 are not duplicates.

This patch adds a condition to check that a node has a term assigned. It checks the state of a node.

http://drupal.org/node/49089 adds a check that a named term exists. It checks the state of a vocabulary tree. The patch includes a comment saying that it checks if a term is set on a node, but that does not appear to be what the patch implements at all.

ded’s picture

Status: Closed (duplicate) » Needs work

I agree this is not a duplicate of #490898: Conditions on terms.

AlexisWilke’s picture

Title: Condition: terms assigned to content » Using terms in conditions
Status: Needs review » Needs work

Hi guys,

This is definitively not a duplicate of #490898: Condition: does term exist? as it checks whether a node has a certain set of terms assigned.

Note that I'd have two requests here:

1) the explode() works but if I write 3, 5, 6, 7 ... with spaces, then " 5" won't match 5 in the array intersect.

$rule_tid_array = explode(',', $settings['tid']);

2) if we have such a test, adding one flag would allow us to test that ALL the terms were selected in the node (i.e. count($rule_tid_array) = count(intersect_array([...])) is TRUE.)

And a side note, the 'help' is quite wrong:

'help' => t('You should make sure that the used vocabulary exists in the given content type. The condition returns TRUE, if the node has the given taxonomy.'),

since this test is of terms assigned to a node and not vocabulary (which wouldn't be as useful... and since each term has a unique tid, it doesn't matter too much whether a specific vocabulary is attached to a node. If the term exists, you can infer that the taxonomy is attached.)

Thank you.
Alexis Wilke

AlexisWilke’s picture

Title: Using terms in conditions » Condition: terms assigned to content
westie’s picture

+1 subscribing

Katrina B’s picture

I had subscribed to another issue, thinking it might be related to the problem I'm trying to solve -- but this issue thread might be closer to what I'm looking for, as I need to be able to create this kind of Rule: "If node has (this term) attached to it, then (do this)."

The difficulty I'm facing is that I'm not allowed to patch modules, due to restrictions at my job, so I'm hoping this feature will eventually be added to Rules.

tribsel’s picture

same problem as in #28

tekken’s picture

subscribing

tekken’s picture

Status: Needs work » Needs review

#8: rules-many-additions.patch queued for re-testing.

Encarte’s picture

subscribe

Anonymous’s picture

Title: Using terms in conditions » Condition: terms assigned to content
Status: Needs work » Needs review

subscribing

Artusamak’s picture

Let's focus on small steps, here is a patch exposing the condition "A node has specific term(s)", you can select the vocabulary where to select the term (or multiple terms), to narrow the list of term displayed and then you just have to pick the terms you want to match as a condition.

Please review. [Do not test this patch but the one in the comment below. Thanks]

Artusamak’s picture

Fixing a typo.

Haza’s picture

Status: Needs review » Needs work

Seems only to works for one term.

Exemple rules : Display a message when a node is saved with a taxonomy term attached.

One vocabulary, 3 terms ID (t1, t2, t3)

Test 1 :
rules : one condition > one term attached t1
New content : t1 is attached
Result : ok

Test 2 :
rules : one condition > NEGATE one term attached t1
New content : t1 is not attached
Result : ok

Test 3 :
rules : one condition > NEGATE one term attached t1
New content : t2 is attached
Result : ok

Test 4 :
rules : two condition > term attached t1 and t2
New content : t1 & t2 are attached
Result : nok

As long as there is only one term, that work very well.
If the conditions is about two or more term, it no longer work.

Also, if checked negate checkbox, then save the first step of the form, checkbox is no longer checked.

AlexisWilke’s picture

I think that the inner foreach() loop in #56 is wrong.

+    foreach($settings['taxonomy_node_terms_are'] as $term) {
+      foreach($node->taxonomy as $tax_vid => $tax_tid) {
+        if ($tax_tid == $term) {
+          $match = TRUE;
+        }
+        else {
+          $match = FALSE;
+        }
+      }
+      if (!$match) {
+        return FALSE;
+      }
+    }

I would imagine that the $match = TRUE; should be followed by a break statement. And the $match = FALSE should be set before the loop. Something like this:

+    foreach($settings['taxonomy_node_terms_are'] as $term) {
+      $match = FALSE;
+      foreach($node->taxonomy as $tax_vid => $tax_tid) {
+        if ($tax_tid == $term) {
+          $match = TRUE;
+          break;
+        }
+      }
+      if (!$match) {
+        return FALSE;
+      }
+    }

Thank you.
Alexis

anrikun’s picture

Subscribing.

hillaryneaf’s picture

subscribing

anrikun’s picture

Title: Condition: terms assigned to content » Condition: content has term
Status: Needs work » Needs review
FileSize
2.19 KB

Here is a new patch.
It is different from the previous one: Evaluates to TRUE, if the given content has one of the selected terms.
I have changed this to mimic the way other built-in Rules conditions work.
Because of the way free tagging terms are saved, free tagging terms are not currently fully supported.

fago’s picture

+/**
+ * Condition: Check for selected terms
+ */

Missing trailing point ;)

From looking at the code, the patch looks fine. As this is already possible in d7, it's fine adding it to d6 too. However, as I'm busy with d7 development I'd like to get some testers/reviews for that before we commit it.

>Because of the way free tagging terms are saved, free tagging terms are not currently fully supported.
That's fine.

I'm a bit worried about loading *all* terms into a big vocabulary. Is this feasible to do on sites with big big vocabularies? Any testers? :)

Also, term names aren't unique so it might be a good idea to append (Term id: X) to the name in the select, so users are able to distinguish multiple terms having the same name.

anrikun’s picture

As this is already possible in d7...

@fago: I wanted to have a look at the way it's done in D7 but I can't find it. Can you point me which file to open?

AlexisWilke’s picture

Yes, the select needs to be a text field a la Tags where people can type the term(s) and have an auto-complete. Anything over 100 terms and you'll blow up the browser!

Thank you.
Alexis Wilke

anrikun’s picture

Status: Needs review » Needs work

Let's revert to "Need work" then.

But I'm not sure if it is possible to do it like tags: term names are not unique and there might be several terms sharing the same name across all vocabularies.

Artusamak’s picture

Because this feature is needed and has been opened 2 years ago, we can start with the actual patch and then open a new issue to scale better. What do you think about that?

anrikun’s picture

@Artusamak: I think so.
But I would like to have a look at this in D7 (See #62, #63). But is it really in D7 :-|?

anrikun’s picture

Status: Needs work » Needs review

Let's wait for some more reviews...

anrikun’s picture

Here is an updated patch:
- @fago: added the missing trailing point ;-)
- added a call to check_plain() on $vocabulary->name

AlexisWilke’s picture

I think that the auto-complete will work by just and simply adding the '#autocomplete_path' as shown below. This is assuming we have a specific vocabulary (i.e. $vid).

        $form['taxonomy']['tags'][$vocabulary->vid] = array(
          '#type' => 'textfield',
          '#title' => $vocabulary->name,
          '#description' => $help,
          '#required' => $vocabulary->required,
          '#default_value' => $typed_string,
          '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
          '#weight' => $vocabulary->weight,
          '#maxlength' => 1024,
        );

Thank you.
Alexis Wilke

Artusamak’s picture

Status: Needs review » Needs work

Why is the vocabulary configuration has been removed? I think it really makes sense to narrow the list of terms loaded.
I'm not in favour of the autocomplete option which may only appropriated on large vocabularies but most of the time you just want to pick terms from a short list of terms. I think it's less easy to use when you want several terms.

anrikun’s picture

Status: Needs work » Needs review

Why is the vocabulary configuration has been removed?

The patch I have submitted is just a different one with a different approach. It allows to select terms across different vocabularies.
I agree that we have to find a way to narrow down the list of terms loaded, but we cannot restrict term selection to only one vocabulary.
Letting this as Needs review won't hurt meanwhile as it is just a "Needs UI improvement" problem.

skobe’s picture

subscribing

mashizhao’s picture

#69's patch works beautifully. Thanks.

crifi’s picture

Status: Needs review » Reviewed & tested by the community

Yeah, patch #69 works perfectly.

crifi’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, I must revoke this status. If you're using the "tags" setting of the vocabulary ("Terms are created by users when submitting posts by typing a comma separated list."), the condition rules_condition_content_has_term() always fails, since $node->taxonomy does not contain an array of taxonomy IDs.

anrikun’s picture

Status: Needs work » Needs review

@crifi:
As stated at #61: "Because of the way free tagging terms are saved, free tagging terms are not currently fully supported."
At #62, fago answered that this is fine.

crifi’s picture

The minimum is to insert a warning message or alter the vocabulary form. The tag vocabulary is a drupal core feature and hence until a consideration, this feature here has a bug. In my opinion features with new bugs shouldn't be committed and "needs work".

anrikun’s picture

Status: Needs review » Needs work

Well it is not a bug but something that is not supported yet.
I agree that a notice should be displayed to user to inform him about this.
Let's revert this back to "needs work" if you prefer.

rfsbsb’s picture

Where do you guys think this notice should be shown? I can create the patch with that.

anrikun’s picture

On the rule's configuration form I guess.
See function rules_condition_content_has_term_form()

rfsbsb’s picture

I was thinking that should be better if instead just show a notice, would be better to not allow users use tags vocabulary hiding the options and showing a warning about it.

Another option is to make a small change in rules_condition_content_has_term to detect if it is tags and do the validation...

I don't know what is better... what do you think?

AlexisWilke’s picture

The best would be to support free tagging... 8-)

Otherwise, it's nice to have a notice when you create the rule, but then you can go to the taxonomy and change the vocabulary from not being free tagging to free tagging and it breaks anyway!

Thank you.
Alexis Wilke

rfsbsb’s picture

I took #69 patch and made a small modification to accept free tagging.

I haven't added any message to warn the user. Do you think it should have any kind of warning? If so, any suggestion?

anrikun’s picture

Status: Needs work » Needs review

@rfsbsb:
If your patch adds support for free tagging (it does right?), there is no need for any warning.
Let's mark it as needs review.

rfsbsb’s picture

@anrikun yes it adds support to free tagging.

Good. I appreciate if someone could test it too.

crifi’s picture

Thanks for the new patch, rfsbsb. Adding the free tag feature is the best solution. I will review the patch as soon as possible with all possible test cases (free tag yes/no, more than one tag in vocabulary, more than one tag in condition,...).

crifi’s picture

I've no problems found. The patch works here. My attached one only changes some typos and coding standards.

anrikun’s picture

Status: Needs review » Reviewed & tested by the community

Nice! I had noticed these typos and coding standards problems too.
If the patch works and code is clean, I guess we can RTBC it.

Artusamak’s picture

Status: Reviewed & tested by the community » Needs work

The code is not clean yet, comments must start with a capital letter and finish with a point.
Otherwise it looks good.

fago’s picture

+++ b/rules/modules/taxonomy.rules.inc
@@ -276,5 +276,64 @@ class rules_data_type_taxonomy_vocab extends rules_data_type {
+      'help' => t('Evaluates to TRUE, if the given content has one of the selected terms.'),

I don't think the comma is needed here.

+++ b/rules/modules/taxonomy.rules.inc
@@ -276,5 +276,64 @@ class rules_data_type_taxonomy_vocab extends rules_data_type {
+  // using taxonomy as a local variable

Start capitalized and end with a trailing point.

However, this comment really isn't necessary. Comments should describe what is not obvious.

+++ b/rules/modules/taxonomy.rules.inc
@@ -276,5 +276,64 @@ class rules_data_type_taxonomy_vocab extends rules_data_type {
+      if (in_array($tid, $tids)) {

Better builds the array $tids by using $tids[$tid] = TRUE or = $tid. So you can check using isset($tids[$tid]) what is faster. (in_array() has to loop over the array)

rfsbsb’s picture

Status: Needs work » Needs review
FileSize
2.93 KB

I'm sending a new patch. It's a merge of patch in #84 and #88 with @Artusamak and @fago suggestions/corrections.

I hope this one is okay :-)

crifi’s picture

In my opinion we should only use one of the array element count functions: count() or sizeof().
The PHP documentation says: sizeof() is an alias of count()

rfsbsb’s picture

My bad. I've forgot to apply this change that was suggested in 88.

the patch including this change.

rfsbsb’s picture

Hi guys. Does have anyone tested it? Is it RTBC?

trillex’s picture

Status: Needs work » Needs review

Having looked at this function in Drupal 7, I must also ask, where is it? :)

The content has term condition, that is.

crifi’s picture

Status: Needs review » Reviewed & tested by the community

I have done some black-box-tests on rules_condition_content_has_term() which is the main critical function. All tests are successful. I have all other functions reviewed and functionality is tested. So this is RTBC now!

underq’s picture

Thx for this last patch but i was some error with foreach & empty taxonomy.

I did a patch

Status: Reviewed & tested by the community » Needs work

The last submitted patch, rules_condition_content_has_term.patch, failed testing.

underq’s picture

Ensure the patch only contains unix-style line endings.

Unix ... :D

rfsbsb’s picture

Status: Needs review » Needs work

Hi underq can you explain which conditions the patch in #94 can cause the errors you mentioned? I tried some stuff and couldn't get any error.

anrikun’s picture

Status: Needs work » Needs review
underq’s picture

Hi rfsbsb,

I was 2 taxonomy vocabulary on a content type and i was an array like that in $taxonomy

  $taxonomy = array (
    [20] => ,
    [32] => 10,
  );
rfsbsb’s picture

Thanks @underq!

Indeed there was this little problem. While checking your patch I've found another bug in my implementation to allow tags and I've fixed it in this patch.

crifi’s picture

Interesting update. For my advanced education: How can I have an empty taxonomy array value (#103)? ;-) Thanks for pointing this out!

rfsbsb’s picture

Hi @crifi in fact the array @underq pointed out isn't accurate.

The array you got when using two vocabularies in a node and filling only one you got a array like the one below:


$taxonomy = array(
  6 => NULL,
  3 => array(
    5 => 5
  )
);
mpavankumar’s picture

after adding this patch i can see a new condition 'Content has term' in Rules, but i can not see terms listing of any vocabulary for selection. I think i am missing something, but could not figure it out. Can anyone give some pointers.

rfsbsb’s picture

Hi mpavankumar indeed there was an error in last patch.

I think this one solve everything now.

underq’s picture

Hi, I have some error with this patch

warning: Illegal offset type in /sites/all/modules/rules/rules/modules/taxonomy.rules.inc on line 335.

I solved with this one

Status: Needs review » Needs work

The last submitted patch, rules_condition_content_has_term-343403-109.patch, failed testing.

fago’s picture

You need to roll patches with -p1.

Patch basically looks good to me, though I've not tested it.

rfsbsb’s picture

Status: Needs work » Needs review
FileSize
3.23 KB

Hi guys, I've took underq patch and fixed in a different manner.

I've done a lot of tests and I think now it's ok.

Tests are welcome.

rfsbsb’s picture

Did anybody tested it? Does anybody confirm if it works?

underq’s picture

I will test today and try to do a simple test if I have some courage

underq’s picture

I have do some test (but it is only the second time that I create test code ;) )
and some change for passe this test

Status: Needs review » Needs work

The last submitted patch, rules_condition_content_has_term-343403-115.patch, failed testing.

underq’s picture

Status: Needs work » Needs review

Hi rfsbsb,

I was stupid when I created this patch. I tested your's today and it works nicely with me ;)

rfsbsb’s picture

Thanks for testing.

Can anyone else test it and mark the patch as RTBC?

vlooivlerke’s picture

Thanks #112 works

Thanks again rfsbsb
This enables me to do some amazing stuff.

rfsbsb’s picture

Hi vlooivlerke, it's a pleasure :-)

If you think it's ok, would you please mark it as rtbc?

Thanks guys

vlooivlerke’s picture

I tested it with a small rule

I am building extensive rules on a production site this week and will then set it to rtbc
Thanks again

Anonymous’s picture

I am very thankful I found this thread. I too needed to generate a system email when someone created a node with a certain taxonomy term selected.

I applied the patch above at http://drupal.org/node/343403#comment-5236684 but I am still not able to get this to work. I believe my inc files were patched correctly but could someone take a look please if you have a minute? I am not sure why this isn't working on my site. I must be missing something. I tested a general rule for sending an email and it worked but not with taxonomy terms.

My rule is:

Event: after saving new content

Conditions: if content is published
and
if content type is News and Events
and
if content has term Student Employment

Action: send mail to arbitrary address

Thanks so much!

perlgal’s picture

Thanks #112 works
Thank you rfsbsb!

rfsbsb’s picture

Hi guys, can anyone mark it as RTBC? Is it really ok?

vlooivlerke’s picture

here is my 20c,

I would have marked this as RTBC, but for some reason this rule only works on very simple rule sets. The minute I use it in more complicated rules it fails. I love this function but I cant put my finger on where it fails. I am trying to get roles to be assigned when a term is selected.

anrikun’s picture

@vlooivlerke:
Are you sure that your rule itself is not faulty here?
Maybe you could post it.

Encarte’s picture

@vlooivlerke, role changing is not an easy action to configure. Are you sure you have the necessary permissions correctly set? The acting user needs to have permission to change roles. Does your rule work if you try a condition other than Content has term?

AlexisWilke’s picture

Encarte,

I've set roles many times from any user (Except Anonymous) and it worked just fine. In software from Rules it doesn't check permissions as far as I know.

Thank you.
Alexis

kaizerking’s picture

It may be relevant to consider to include this issue TAC Lite Rules integration
if it doesn't fit here my apologies plz
EDIT:Sorry, i didn't see that the current issue here is for 6x issue,I am keeping it here for anyones reference.
the TAC Lite rules integration issue is for 7x

kaizerking’s picture

can this be used in D7?
I need this ureently

rfsbsb’s picture

Hi @kaizerking, this patch is for D6 only.

@vlooivlerke can you provide a more detailed revision of what you've found?

vlooivlerke’s picture

Status: Needs review » Reviewed & tested by the community

I found this to work.
Tested it with various rule combinations and on live and local server.

I patched it manually, so cant comment on that

fago’s picture

Status: Reviewed & tested by the community » Fixed

thanks, I committed the patch from #112!

For d7, things work a bit different here as terms are never generally assigned to nodes any more, but they are assigned to nodes by fields. Thus, you'll have to check per-field, which can be done with the condition "List contains item".

kaizerking’s picture

@fago, is there any help documentation on this, on "list contains item" list means which list? or where do we create a list?
My requirement is if job per template has term reference, i want to grant access to the user if he has "equal to" or "one of" term references in his/her profile2-field collection field (Work experience)- term references, it is proving very difficult for me kindly guide/help

hedac’s picture

just tried last dev.. but the condition always return FALSE... I'm creating a forum topic with a certain term and the condition has term.. with that term selected... not sure why it is not working. Maybe because the forum is inside a container.. which gives it a different taxonomy depth?

zvischutz’s picture

Hi there
It did return FALSE all the time as @hedac mentioned .
I changed the loop on bottom of rules_condition_content_has_term lines 325-338 to the following and it worked.

    foreach ($taxonomy as $tid => $vocab) {
      if (!empty($vocab) && is_array($vocab)) {
        foreach ($vocab as $term) {
	  drupal_set_message('ttt' . var_export($term,true));
          $tid = is_object($term) ? $term->tid : (is_array($term) ? reset($term) : $term);
          $tids[$tid] = $tid;
        }
      }
      else {
        if (!empty($vocab) && is_numeric($vocab)) {
          $tids[$vocab] = $vocab;
        } else if (is_object($vocab)) {
	  drupal_set_message('ppp' . $tid);
   	  $tids[$tid] = $tid;
	}
      }
    }

Best
Zvi

Status: Fixed » Closed (fixed)

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

soundboy89’s picture

Component: Rules Engine » Rules Core
Status: Closed (fixed) » Fixed

Will this eventually make it to a release version of the module for D6?

Status: Fixed » Closed (fixed)

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

jvieille’s picture

Status: Closed (fixed) » Needs review

Incorrect status

vlooivlerke’s picture

This rule is expensive on the juice

0 ms "After updating existing content" has been invoked.
0.14 ms Executing the rule "Content has term Holiday Accommodation" on rule set "After updating existing content"
0.371 ms Condition "Updated content is Wiki" evaluated to TRUE.
0.527 ms Condition "Content has term" evaluated to FALSE.
0.602 ms Executing the rule "Content has term Holiday Accommodation" on rule set "After updating existing content"
0.781 ms Condition "Updated content is Wiki" evaluated to TRUE.
0.931 ms Condition "Content has term" evaluated to FALSE.
1.014 ms Evaluation of "After updating existing content" has been finished.

My rule works like this, after updating existing content and content has term "holiday accommodation"

In the top code the content has no term selected, but look at this part:
0.14 ms Executing the rule "Content has term Holiday Accommodation" on rule set "After updating existing content"

and

0.602 ms Executing the rule "Content has term Holiday Accommodation" on rule set "After updating existing content"

Why is it doing this? It should not execute at all coz there is no term (0.931 ms Condition "Content has term" evaluated to FALSE.)

Here is the code if I select a term, but it still do some execution.

0 ms "After updating existing content" has been invoked.
0.128 ms Executing the rule "Content has term Holiday Accommodation" on rule set "After updating existing content"
0.362 ms Condition "Updated content is Wiki" evaluated to TRUE.
0.534 ms Condition "Content has term" evaluated to TRUE.
0.792 ms Action execution: "Show a configurable message on the site"
0.907 ms Executing the rule "Content has term Holiday Accommodation" on rule set "After updating existing content"
1.1 ms Condition "Updated content is Wiki" evaluated to TRUE.
1.261 ms Condition "Content has term" evaluated to FALSE.
1.336 ms Evaluation of "After updating existing content" has been finished.
AlexisWilke’s picture

It's probably when it's loading your terms... Do you have many terms in the taxonomy you are testing with?

Alexis

vlooivlerke’s picture

Yes, over 300 terms in 3 tiers.

But why is it loading it, to see that there is no term selected?

underq’s picture

This rules always return false in this case.

Exemple :
1 - I create a new node without term.
2 - I have a rules wich start when I save this node and execute rules_action_taxonomy_term_assign_to_content($node, term1, $settings); with term1.
3 - I have a second rules wich start after the first one and check if node have term1 rules_condition_content_has_term($node, $settings = term1); but this function return false.

This happen when $node->taxonomy[] is a stdClass like after rules_action_taxonomy_term_assign_to_content(); and this function check if $taxonomy is an array or an integer.

foreach ($taxonomy as $vocab) {
      if (!empty($vocab) && is_array($vocab)) {
        …
      }
      else {
        if (!empty($vocab) && is_numeric($vocab)) {
          …  
        }
      }
    }
 
underq’s picture

This patch try to resolve comment #343403-144: Condition: content has term.

Reviews are welcome :)

soundboy89’s picture

I applied #145 and worked like a charm. Thanks underq!

qasimzee’s picture

#145 works like a charm

kaizerking’s picture

does this only works for nodes? or works for entities as well?
ex:"entity has term"

eelkeblok’s picture

Status: Needs review » Needs work
FileSize
1.5 KB

Thanks for all the work on this patch. @kaizerking: This is an issue for 6.x, so not really :) A similar question about how to accomplish this in D7 was asked and answered further up (if you need more help, please ask somewhere else, this issue is strictly for making changes to the 6.x branch of this module).

I ran into the same problem, that my terms were not recognized because they showed up as objects in the taxonomy array in the node. I applied the patch from #145. Although it does appear to work, when stepping through it using XDebug I found some weird behaviour; it treats the term objects in the taxonomy array as arrays themselves (foreach-ing over the object), which results in each member variable of the object to be treated as a term in its own right. Although this means that functionally the condition will trigger when the sought term is applied, it also means the functionality is not quite correct and I think could even lead to false positives.

I'll be attaching a patch later to correct this.

eelkeblok’s picture

Status: Needs work » Needs review

Whoops. Actually attached the patch already :) The patch attached to #149 treats the check for is_object as the separate case that it is.

Status: Needs review » Needs work

The last submitted patch, rules_condition_content_has_term-343403-149.patch, failed testing.

eelkeblok’s picture

Component: Rules Core » Module Integrations
Status: Needs work » Needs review
FileSize
1.42 KB

Sorry, rolled the patch from my dev environment so the path was incorrect. This should apply correctly.

dblais’s picture

It's work now. Thank you! . Before, has_term was never TRUE because $vocab was a object, so tid was always empty.

Can you integrate it the next relase soon?

Someone else have this issue:

https://drupal.org/node/1891716

eelkeblok’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Does this qualify as RTBC? :)

fago’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Patch violates coding standard. Also, please do not re-open fixed issues - instead create a new one and link it here to inform potentially interested people. Setting back to the status of the original issue - fixed.

eelkeblok’s picture

Wow, that was way back in comment #141, I wasn't even aware this was a re-opened issue.