Search code examples
drupaldrupal-7

Drupal using rules: User is in organic group logic?


I am trying to make a user have a role dependent on a list of values for an organic group using the rules module. I can't use the data comparison field because that only seems to compare exact list values. For example, if I had the numbers 1,2,3,4 in my data compares but I have 1,2,3,4,5 values in my organic group list, I cannot assign the role. None of the other choices I have make sense.

My question is: How do I assign a user to a role in Drupal 7 using the Rules module, based on the value in an organic group list?

Thank you for the help in advanced.


Solution

  • I think you have to create your own rules condition. This is quite simple by using a custom module.

    First you have to implement hook_rules_condition_info.

    function mymodule_rules_condition_info() {
      return array(
        'mymodule_og_condition_compare' => array(
          'label' => t('Textual comparison'), 
          'parameter' => array(
            'text1' => array(
              'label' => t('Text 1'),
              'type' => 'text',
            ), 
            'text2' => array(
              'label' => t('Text 2'),
              'type' => 'text',
            ),
          ), 
          'group' => t('Rules'),
        ),
      );
    

    Then you must create a custom function, that compares your values and returns TRUE or FALSE.

    function mymodule_og_condition_compare($node, $node_unchanged){
      //Compare values an return TRUE or FALSE
    }