5

I'm using Entity References and CiviCRM Entity to create some limited silent auction functionality.

  • In CiviCRM, I have an "In-Kind" contribution type with some custom fields for each donation of an item to be auctioned off.
  • In Drupal, I have an "Auction Package" content type for each group of one or more items that will be purchasable at auction.
  • I created an entity reference field in the auction package so that you can select which items are part of each package. (So you could combine, say, a hotel's gift of a one-night stay with a restaurant's donated gift certificate.)

So I've figured out how to pull CiviCRM information into Drupal. But is there a way to leverage the entity reference field in reverse to pull info from Drupal back into CiviCRM? I'd like to have a reference field in the contribution, or record the package number from the Drupal entity in the Civi contribution. How can I do this?

Note: This is a new system, and I'm fairly new to CiviCRM, so I'm open to doing things differently if reworking anything about the way I have this set up would make this work better.

3
  • What entity does your entity reference field reference? Are you using CiviCRM contribution page to sell these products? Are you wanting to populate a custom field on the CiviCRM record with the node_id of the "Auction Package"? Commented Apr 5, 2015 at 20:32
  • 1) The referenced entity is a Civi Contribute gift record. 2) At this point we're not trying to "sell" the Drupal auction package entities via CiviCRM (although that would be a cool future feature.) 3) My first choice would be a reverse reference field from Civi back to the Drupal node, but that didn't seem possible so we're settling for basically what you've said - a custom field on the CiviCRM record populated with info from a field (not the NID) on the "Auction Package" Drupal node. Commented Apr 19, 2015 at 2:28
  • 1
    I think that's what you have to do, either with Rules or a custom Drupal module, update the CiviCRM data after the Drupal bit is created or updated. Commented Apr 19, 2015 at 14:38

3 Answers 3

3

This is a great question and frankly I've found it challenging to "seamlessly" integrate Drupal and Civicrm. I have successfully used the Drupal Rules module and Civicrm Entity to make Civicrm updates. Alternatively, you can use the rule module and a PHP snippet to invoke the Civi API and make the update.

The civicrm_entity / rules approach does not let you load multiple entities directly but you can use multiple referenced drupal entities.

Civicrm_entity can also write fields directly but you would have to write some code to edit the entity.

2
  • the issue mentioned in this comment has been resolved, there is a patch:drupal.org/node/2316341#comment-9800613 and the 2.x-dev download on D.O has this patch merged in Commented Apr 14, 2015 at 23:19
  • Ah ha, Rules! I think this is the answer I was looking for but I've held off on accepting it as I haven't managed to get it working yet. Maybe you all can help me figure out what I'm doing wrong? Here's my rule: Event: After updating Auction Package content (I'll need a second rule to fire after creating a node). Elements: Entity has field_i_want_to_copy_to_Civi & reference field. Actions: Loop through reference field. Fetch CiviCRM entity by property... um, now I'm doing something wrong - what do I do to update a field in the referenced CiviContribute records? Commented Apr 19, 2015 at 2:43
3

So my understanding of your use case is that you want to record in the back end in-kind donations related to items to be auctioned off in bundles. I assume that each item has its own valuation, and that you are mainly interested in getting a custom field on the contribution to reference an item. (I would guess the bundles of items are the sales side of the auction, and that multiple in-kind donations can be dealt with through separate contributions for each item.) Setting up contribution pages and price sets to reference the items in order to expose the items for auction would be something else again.

I would make the custom field an integer, then in code on buildForm hook for the relevant form I would create a select widget that looked up the Drupal entity. If there were budget to improve usability in a minimal fashion I would add a link beside the field that creates a popup form to Add the Drupal entity, and on form close I would refresh the select lookup values. On view custom code needs to convert entity id into entity title or something, maybe an image and caption. If the value of the item is stored in Drupal then when it is selected I would use it overwrite the line item value in CiviCRM.

A similar process could be used to link the donations corresponding to winning bids to the bundle entities that were won.

3

One possibility would be to use views module to create a view that displays auction package nodes, with a contextual filter for the contribution reference field. Then you provide a block display and configure the block to show on contribution pages; it should show the package that is referencing that contribution.

This doesn't pull any Drupal entity data into the CiviCRM database, but it should allow you to display the entity data for the auction package that is referencing the contribution.

Often times it is ideal to keep the Drupal entities in Drupal and the CiviCRM entities in CiviCRM and connect them using reference fields. You should still be able to display them side by side on the same page (using Views) in virtually any context or use-case.

1
  • I added a bit more about my reasoning behind this approach.
    – LunkRat
    Commented Apr 14, 2015 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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