1

trying to implement the following workflow - New Organisation Membership approval in CiviMember creates OG in Drupal called after Org, with Org drupal account as OG admin. I'm looking at maybe using Rules, but I'm a bit new to the module, any tips appreciated.

CiviCRM 5.3.0 Drupal 7.59

2

Unfortunately Drupal rules module is not triggered on CiviCRM membership CRUD function and CiviRules does but doesn't provide option to perform any CMS changes like creating OG groups in your case. I would recommend to create an extension or drupal module and use CiviCRM post hook to create OG group. eg:

function extensions_civicrm_post($op, $objectName, $objectId, &$objectRef) {
  if ($objectName == 'Membership' && $op == 'create') {
    try {
      $orgName = civicrm_api3('Contact', 'getvalue', [
        'return' => "organization_name",
        'id' => 1,
        'contact_type' => "Organization",
      ]);
    }
    catch (CiviCRM_API3_Exception $e) {
      // Not a organization contact
      return;
    }
    // get the user id who will controll this group either Employee of relationship?
    $userId = 1;

    //create OG
    $node = new stdClass();
    $node->type = "og_node"; // use the machine name of OG group node type
    node_object_prepare($node);
    $node->title = $orgName;
    $node->language = LANGUAGE_NONE;
    $node->uid = $userId;
    $node->group_group[LANGUAGE_NONE][0]['value'] = TRUE;
    node_save($node);

    $roles = array_flip(og_roles('node', 'og_node', $node->nid));
    og_role_grant('node', $node->nid, $user->uid, $roles[OG_ADMINISTRATOR_ROLE]);
    $values = [
      'entity_type' => 'user',
      'entity' => $userId,
    ];
    og_group('node', $node->nid, $values);
  }
}

HTH

Pradeep

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.