Posted by markusa on March 17, 2013 at 11:43am

I've added a couple of lines to try to expose civicrm groups as entities

//In civicrm_entity.module
function _civicrm_entity_enabled_entities() {
  return array(
    'civicrm_event' => 'event',
    'civicrm_contact' => 'contact',
    'civicrm_participant' => 'participant',
    'civicrm_relationship' => 'relationship',
    'civicrm_relationship_type' => 'relationship_type',
    'civicrm_activity' => 'activity',
    'civicrm_entity_tag' => 'entity_tag',
    'civicrm_membership' => 'membership',
'civicrm_group' => 'group', // add this
  );
}
function _civicrm_entity_labels($entity) {

  $labels = array(
    'civicrm_event' => 'title',
    'civicrm_contact' => 'display_name',
    'civicrm_participant' => 'source',
    'civicrm_relationship' => 'description',
    'civicrm_relationship_type' => 'description',
    'civicrm_activity' => 'subject',
    'civicrm_entity_tag' => 'tag_id', // OK I'm just putting in something that won't error for now
    'civicrm_membership' => 'id', // ditto
'civicrm_group'=> 'id', //add this 
  );
  return $labels[$entity];
}

This works as well, and Rules events are created and triggered on update and save. You can make a list of groups in views, with all the group table fields.

But unlike the other civicrm entities, there are no views relationships available.

So I tinkered with the civicrm drupal views module...if you patch civicrm.core.inc following the diff below
The first bit will give you a group relationship open in things like lists of contacts. Its not really necessary it seems because of civicrm views handling but it may be necessary to have actually views relationships

diff -b -B -r original/civicrm.core.inc hacked/civicrm.core.inc
94a95,98
> 'civicrm_group' => array(
> 'left_field' => 'contact_id',
> 'field' => 'id',
> ),

2081a2086,2093
> 'relationship' => array(
> 'base' => 'civicrm_group',
> 'title' => 'Group Info',
> 'left_field' => 'contact_id',
> 'field' => 'id',
> 'handler' => 'views_handler_relationship',
> 'label' => t('CiviCRM Group'),
> ),

Comments

eileenmcnaughton’s picture

I've added this in.

WRT to the relationship - it feels like it should be a join on created_id? @ this stage most of the relationships are being managed by the civicrm_views module but it would make sense later to move the management to this module

eileenmcnaughton’s picture

Status: Active » Closed (fixed)