I'm trying to figure out a problem with the 7.x-2.2 release, where I'm trying to do the following (which I've done with some earlier releases of Rules 2.x):

  1. I want to wrap a non-Drupal object (in this case, items from CiviCRM, such as contact or events) using RulesIdentifiableDataWrapper. This in theory should be a good fit, since while it's really impractical to expose them directly as entities (it would be insane to let Entity API write directly into CiviCRM's database, for example), the items do have distinct, serial IDs.
  2. I'd like to use CiviCRM's hook system to call rules_invoke_event() to trigger various interesting events in these objects' life cycle in CiviCRM, and pass a reference to the object via rules_invoke_event().
  3. I need to be able to inspect the object using a Rules condition in order to determine what action invoke on them

I'm declaring the data type to Rules something like this:

/**
 * Implements hook_rules_data_info().
 */
function civicrm_new_rules_rules_data_info() {
  return array(
    'civicrm_contact' => array(
      'label' => t('CiviCRM contact data'),
      'wrap' => TRUE,
      'wrapper class' => 'ContactRulesWrapper',
    ),
  );
}

where class ContactRulesWrapper is declared in another file, and exposed in my .info file as usual.

My event declaration looks like this:

function civicrm_new_rules_rules_event_info() {
  $default_variables = array(
    'civicrm_contact' => array(
      'type' => 'civicrm_contact',
      'label' => t('CiviCRM contact object'),
      ),
  );
  $items = array(
    'civicrm_contact_created' => array(
      'label' => t('A contact has been created.'),
      'group' => t('CiviCRM Alt Rules'),
      'variables' => $default_variables,
    ),
  );
  return $items;
}

I'm declaring a condition to examine the the wrapped contact, which is declared in civicrm_new_rules_rules_condition_info(), the relevant portion like this:


function civicrm_new_rules_rules_condition_info() {
  $def = array(
    'civicrm_contact_test_token' => array(
      'label' => t('Test a member token value'),
      'parameter' => array(
        'civicrm_contact' => array('type' => 'civicrm_contact', 'label' => t('CiviCRM contact object')),
        'key_name'  => array(
          'type' => 'text',
          'options list' => 'civicrm_new_rules_rules_add_keyname_options',
          'label' => t('Key name for a voter data slot'),
          'restriction' => 'input',
        ),
        'key_value' => array(
          'type' => 'text',
          'label' => t('Value of this key to test for'),
          'restriction' => 'input',
        ),
        'operator' => array(
          'type' => 'text',
          'label' => t('Type of Test'),
          'options list' => 'civicrm_new_rules_rules_choice_of_operator',
          'restriction' => 'input',
        ),
        
      ),
 
      'group' => t('CiviCRM Alt Rules'),
      
    ),
  );
  return $def;
}

Now here's the problem: if I create a new Rule where the triggering event is 'civicrm_contact_created', when I select the 'Test a member token value' item from the popup, I don't get any configuration UI; in particular, I don't get the Data Selection screen for this item.

I've done two other implementations of similar Rules modules, and have not had this problem. I'm not sure if I'm doing something subtlely wrong with my implementation, or if 2.2 just doesn't behave the same as the 7.x-2.1.

In advice as to how to debug this is welcome; the way the AJAX is hooked in via the various plugins makes this module a harder to debug than most other modules in Contrib.

Comments

Torenware’s picture

This may be related to

http://drupal.org/node/1792524

and

http://drupal.org/node/1842012

This is a bug in 2.2, not sure how to get the developer's attention so it gets fixed.

fago’s picture

Category: bug » support

It's up to the ContactRulesWrapper to provide properties - if it provides some they will be picked up. The data selectors works with what the wrapper gives it.

fago’s picture

Status: Active » Fixed

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