CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • How do I allow a Drupal user to view & edit family members?
Pages: [1]

Author Topic: How do I allow a Drupal user to view & edit family members?  (Read 923 times)

naomisl

  • I post occasionally
  • **
  • Posts: 51
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7.32
How do I allow a Drupal user to view & edit family members?
September 02, 2014, 12:03:55 pm
Here's the setup: I have a webform which, through a combination of Webform Civicrm and Rules, creates multiple contacts. The primary user, a second parent, and a child. It creates the parent-child relationships between them, and also creates a household with the relationship of "is a household member of" for the contacts involved. The primary user then becomes a linked Drupal user account.

All of this is perhaps ancillary to the question, which is as follows:
How do I allow the Drupal user (first parent, the one who filled out the form) to view and edit the related contacts in civicrm? I'm not sure whether to use profiles, or how this should work exactly. Ideally, the parent would then be able to, say, sign up the child for an event, and change the child's information if it had gotten out of date.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: How do I allow a Drupal user to view & edit family members?
September 02, 2014, 12:09:53 pm
1) Make sure the relationships created by the webform are "permissioned".
2) Install this extension: https://civicrm.org/extensions/relationship-permissions-acls
3) Give each of the related contacts on the webform an "Existing Contact" field. Configure that field to set "default value" based on the appropriate relationship to contact 1.
Try asking your question on the new CiviCRM help site.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How do I allow a Drupal user to view & edit family members?
September 02, 2014, 12:11:01 pm
was writing this while Coleman was adding his - am pasting without censoring myself

You can keep using Webforms - which is how we would most likely approach this.

If just using the option in webforms to load the spouse/child isn't specific enough then you could use a View to put a block somewhere, and use links of each of their family members to add their id as cid2=xxx on the webform so it prefills with eg ChildA's data.

Registering for Events can also be done via Webform but will depend on your payment set up.

Primary Contact can also access their dashboard and via that edit the Name/Address type details of their family members.

It may be possible to use a Drupal block approach and have links that put the id for kids on to a civi event rego page but not sure about that.

Hope the above gives you something to work on
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

naomisl

  • I post occasionally
  • **
  • Posts: 51
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7.32
Re: How do I allow a Drupal user to view & edit family members?
September 02, 2014, 02:25:25 pm
Quote from: Coleman Watts on September 02, 2014, 12:09:53 pm
1) Make sure the relationships created by the webform are "permissioned".
2) Install this extension: https://civicrm.org/extensions/relationship-permissions-acls
3) Give each of the related contacts on the webform an "Existing Contact" field. Configure that field to set "default value" based on the appropriate relationship to contact 1.

This looks like it will work very well, thank you! I am, however, somewhat embarrassingly getting stuck on making the relationships permissioned. How does one go about such a thing? I've installed the extension, so I think (I hope!) once I've got this piece down it should be smooth sailing, but i can't find any reference to it in the guide or elsewhere.

naomisl

  • I post occasionally
  • **
  • Posts: 51
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7.32
Re: How do I allow a Drupal user to view & edit family members?
September 02, 2014, 03:07:24 pm
Wait! I see now how to make the relationships permissioned using the webform. And from the civicrm side, I can add permissions by viewing the contact's relationships. 

Ok, crossing my fingers and hoping it works!

naomisl

  • I post occasionally
  • **
  • Posts: 51
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7.32
Re: How do I allow a Drupal user to view & edit family members?
September 02, 2014, 04:37:53 pm
It works!

It's a bummer that while it works it also throws thes error codes:

Notice: Undefined offset: 8 in wf_crm_webform_base->loadContact() (line 114 of /home/makom/www/www/sites/all/modules/webform_civicrm/includes/wf_crm_webform_base.inc).
Notice: Undefined offset: 9 in wf_crm_webform_base->loadContact() (line 114 of /home/makom/www/www/sites/all/modules/webform_civicrm/includes/wf_crm_webform_base.inc).

The offending line 114 in the php for hte Webform CiviCRM module is highlighted in green in the phrase below:

    // Retrieve relationship data
    if (!in_array('relationship', $exclude) && !empty($contact['number_of_relationship'])) {
      $this->enabled = wf_crm_enabled_fields($this->node);
      for ($r = 1; $r <= $contact['number_of_relationship']; ++$r) {
        $types = array();
        $prefix = "civicrm_{$c}_contact_{$r}_relationship_";
        if (!empty($this->id['cid'][$r])) {
          if (!empty($contact['relationship'][$r]['relationship_type_id']) && $contact['relationship'][$r]['relationship_type_id'] != 'create_civicrm_webform_element') {
            $types = (array) $contact['relationship'][$r]['relationship_type_id'];
          }
          if (!empty($this->enabled[$prefix . 'relationship_type_id'])) {
            $types += array_keys($this->getExposedOptions($prefix . 'relationship_type_id'));
          }
        }
        $rel = $this->getRelationship($types, $cid, $this->id['cid'][$r]);
        if ($rel) {
          $info['relationship'][$r] = $rel;
          // Fetch custom data
          $len = strlen($prefix . 'custom_');
          foreach ($this->enabled as $k => $v) {
            if (substr($k, 0, $len) == $prefix . 'custom_') {
              $custom = wf_civicrm_api('custom_value', 'get', array('entity_id' => $rel['id'], 'entity_table' => 'Relationship'));
              foreach ($custom['values'] as $k => $v) {
                if (isset($v[0])) {
                  $info['relationship'][$r]["custom_$k"] = $v[0];
                }
              }
              break;
            }
          }
        }
      }
    }
    return $info;
  }

Any hints on how to get rid of the error?

naomisl

  • I post occasionally
  • **
  • Posts: 51
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7.32
Re: How do I allow a Drupal user to view & edit family members?
September 02, 2014, 06:22:25 pm
Ok, you are all probably tired of me commenting on my own question by now. But for posterity, here's how I made it work, with help from Coleman. (Thank you Coleman! And thank you petednz for your ideas as well!)

1) Make sure the relationships created by the webform are "permissioned".
Do this by going into the webform civicrm, and making sure every created contact has a relationship to contact1. In the same place as adding the relationship, you will ahve permissions choices. Choose either "can be edited by contact1" or "both can edit each other." For contacts that have already been created incivicrm, or in the event that you are not using a webform, you can add these same permissions when you add a relationship between the contacts from the civicrm side.

2) Install this extension: https://civicrm.org/extensions/relationship-permissions-acls
Simple enough. Follow the directions to install an extension from within civicrm.

3) Give each of the related contacts on the webform an "Existing Contact" field. Configure that field to set "default value" based on the appropriate relationship to contact 1.
After clicking "existing contact" in the civicrm tab of webform, go to the webform tab. For each "existing contact" field, set it to 'static" so that it is hidden, and then choose "default value" as "relationship to contact1." Choose the correct relationship in the dropdown that appears.

4) Hide the error code.
When a user is logged in, PHP will throw an error code if there are any fields to prepopulate that it does not have contact info to use to poluate that field with. To stop this error from being shown to the user, go tothe file /sites/all/modules/webform_civicrm/includes/wf_crm_webform_base.inc in your control panel or FTP program and change line 114 to have an "@" in front of it. So it will go from reading
 $rel = $this->getRelationship($types, $cid, $this->id['cid'][$r]);
to reading
 @$rel = $this->getRelationship($types, $cid, $this->id['cid'][$r]);

5) Ta Da!

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How do I allow a Drupal user to view & edit family members?
September 02, 2014, 07:36:50 pm
well done naomi

it is also possible to have a checkbox where you edit the Relationship Type so that you can always make A have permission over B, ie you don't need to remember to do this, eg all Primary Contacts will automatically be permissioned over

pretty sure it just requires

https://github.com/eileenmcnaughton/nz.co.fuzion.entitysetting/blob/master/README.md
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: How do I allow a Drupal user to view & edit family members?
September 03, 2014, 12:55:45 am
Thanks for the debugging Naomi, I've pushed in this fix which is a bit better (using @ to suppress errors is usually a last-resort):
Code: [Select]
$rel = $this->getRelationship($types, $cid, wf_crm_aval($this->id['cid'], $r));Could you please double check it and make sure it works?
Try asking your question on the new CiviCRM help site.

naomisl

  • I post occasionally
  • **
  • Posts: 51
  • Karma: 0
  • CiviCRM version: 4.5.3
  • CMS version: Drupal 7.32
Re: How do I allow a Drupal user to view & edit family members?
September 03, 2014, 09:29:16 am
Coleman-- That works! I'm not very adept at PHP yet, so suppressing the error was what I could manage. Thank you so much for debugging!

Pete-- Thank you for the extension, I'm definitely looking into adding it. Having the relationships automatically permissioned would be a lot smoother.

And thank you to both of you for helping me figure this out!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: How do I allow a Drupal user to view & edit family members?
September 03, 2014, 12:10:14 pm
Glad to help.
I've pushed that change into webform-civicrm 4.dev so it will be part of the next 4.x release.
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • How do I allow a Drupal user to view & edit family members?

This forum was archived on 2017-11-26.