You are here

function civicrm_entity_rules_event_info in CiviCRM Entity 7

Same name and namespace in other branches
  1. 7.2 civicrm_entity.rules.inc \civicrm_entity_rules_event_info()

Implements hook_rules_event_info().

File

./civicrm_entity.rules.inc, line 77
Implement Drupal Rules integration for CiviCRM

Code

function civicrm_entity_rules_event_info() {
  $events = array();
  $valid_objects = _civicrm_entity_enabled_entities();

  // array('Event' => 'civicrm_event');
  if (is_array($valid_objects)) {
    foreach ($valid_objects as $entity => $civicrm_entity) {
      $entity_name = 'CiviCRM ' . ucwords(str_replace('_', ' ', $civicrm_entity));

      // @TODO consider building the entity name into the argument
      // rather than calling the same argument for each.
      $create_msg = t('Created !entity', array(
        '!entity' => $entity_name,
      ));
      $events[$entity . '_create'] = array(
        'label' => t("!entity has been created", array(
          '!entity' => $entity_name,
        )),
        'group' => $entity_name,
        'module' => 'civicrm',
        'access_callback' => '_civicrm_entity_rules_access',
        'variables' => civicrm_entity_rules_events_variables($create_msg, $entity, $civicrm_entity),
      );
      $update_msg = t('Updated !entity', array(
        '!entity' => $entity_name,
      ));
      $events[$entity . '_edit'] = array(
        'group' => $entity_name,
        'module' => 'civicrm',
        'access_callback' => '_civicrm_entity_rules_access',
        'label' => t("!entity has been updated", array(
          '!entity' => $entity_name,
        )),
        'variables' => civicrm_entity_rules_events_variables($update_msg, $entity),
      );
      $view_msg = t('Viewed !entity', array(
        '!entity' => $entity_name,
      ));
      $events[$entity . '_view'] = array(
        'group' => $entity_name,
        'module' => 'civicrm',
        'access_callback' => '_civicrm_entity_rules_access',
        'label' => t("!entity has been viewed", array(
          '!entity' => $entity_name,
        )),
        'variables' => civicrm_entity_rules_events_variables($view_msg, $entity),
      );
      $delete_msg = t('Deleted !entity', array(
        '!entity' => $entity_name,
      ));
      $events[$entity . '_delete'] = array(
        'group' => $entity_name,
        'module' => 'civicrm',
        'access_callback' => '_civicrm_entity_rules_access',
        'label' => t("!entity has been deleted", array(
          '!entity' => $entity_name,
        )),
        'variables' => civicrm_entity_rules_events_variables($delete_msg, $entity),
      );
    }
  }
  return $events;
}