Back in OG-7.x-1.x, the Rules condition 'Entity is in group' allowed one to select the specific group for which to test by switching from data selector mode to direct input mode - the result was an option list populated with all the groups in the system.

Now in 7.x-2.2 I don't get the same option to choose direct input mode at all, which means I'm not sure how one can use 'Entity is in group' at all - there's no way to select the group(s) against which to test the membership.

I'm not a Rules jockey, and I know that the 2.x branch of OG is very different.

Has the process for testing if an entity is in a group changed since the 1.x branch? Any tips on how to get this kind of test working? Or is this, in fact, a bug - or not-yet-fully-implemented-feature?

Comments

grasmash’s picture

I'm experiencing the same problem. Without direct input mode, how can one specify which group should be checked?

grasmash’s picture

Workaround: rather than using 'Entity is in group', do the following:
- add condition "Entity has field", Parameter: Entity: [node], Field: og_group_ref
- add condition "Data comparison", Parameter: Data to compare: [node:og-group-ref], Data value: 34291

This should accomplish the same thing.

chiebert’s picture

Another workaround that works nicely for my use case (add content to a specific group, based on the value of another field after saving updates): Don't put any of the 'entity is in group' conditional logic in the main Rule. Instead:

1. Create a Rules component that takes as its parameters the group node(s)/entity(ies) you're trying to compare against/add to, as well as the node/entity you want to test/add.

2. Construct the rest of the component according to your required logic - you now have the entity(ies) required to use the Data Selector with, and therefore you can use 'entity is in group' and 'add/remove entity to/from group' conditions and actions. If it still won't let you select your parameterized entity, perhaps add a condition 'entity is group'?

Ideally we should have an implementation something like 7.x-1.x's 'ui class' and OGRulesDataUIGroup. Here's that code from 7.x-1.5, but there are plenty of things that are different in the 2.x branch that I can't seem to translate yet:

/**
 * Implements hook_rules_data_info_alter().
 */
function og_rules_data_info_alter(&$data_info) {
  $data_info['group']['ui class'] = 'OGRulesDataUIGroup';
}

/**
 * UI that adds in the group options list.
 */
class OGRulesDataUIGroup extends RulesDataUIEntity {

  public static function inputForm($name, $info, $settings, RulesPlugin $element) {
    // Add an options list of all groups if there is none yet.
    if (!isset($info['options list'])) {
      $info['options list'] = array('OGRulesDataUIGroup', 'optionsList');
    }
    return parent::inputForm($name, $info, $settings, $element);
  }

  public static function optionsList() {
    return og_label_multiple(og_get_all_group());
  }
}
Yuri’s picture

Issue summary: View changes

Just add a variable of type node and give it a value. Use the variable as the required group.

bpleduc’s picture

@Yuri - Great idea however, this does not work for us.

The defined variable does not appear in the drop down list.

To prove that the variable was added correctly another action "Set a data value" was added and the new variable was shown.