I have CiviCRM 5.12 on drupal 7. I want to create a drupal view containing the next events that are printed if only the contact belongs to an authorized group. That is, when I create an event, I link it to a group with a custom field and in the view, I want to filter the events and keep those reserved for the group containing the contact corresponding to the user drupal. Please can you help me ?


I think you can filter the views using CONTEXTUAL FILTERS. Add group custom field in CONTEXTUAL FILTERS set default value to use below php code

    try {
      $result = civicrm_api3('Contact', 'getsingle', [
        'return' => ["groups"],
        'id' => "user_contact_id",
      return $result['group'];
    catch (Exception $e) {
      return 0;

enter image description here



  • it seems to work. But I've no results. How you reference groups to event custom field? – bass Jun 13 '19 at 14:36
  • I guess you may need to figure out the return statement if logged in user in subscribed to more than 1 group . – Pradeep Nayak Jun 13 '19 at 14:57
  • Sorry, perhaps I miss some thing. Logged in user can be in more than 1 group and, I want to show all events. I think I'm wrong when I link the costum field to the group. – bass Jun 13 '19 at 15:18

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.