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 Drupal Modules (Moderator: Donald Lobo) »
  • How to create a Drupal content field that only accepts CiviCRM contacts.
Pages: [1]

Author Topic: How to create a Drupal content field that only accepts CiviCRM contacts.  (Read 1294 times)

texvet_webmaster

  • I’m new here
  • *
  • Posts: 26
  • Karma: 3
    • The TexVet Initiative
  • CiviCRM version: 4.5.6
  • CMS version: Drupal 7.34
  • MySQL version: 5.5.38
  • PHP version: 5.3.20
How to create a Drupal content field that only accepts CiviCRM contacts.
February 17, 2015, 07:15:10 am
Howdy,

I was composing a question to the forum on how to create a content field that only accepts CiviCRM contacts and in the process I figured out how to do it. Since (in my fairly extensive searching over the past few days) I haven't found a page on the Internet that explains how to do this clearly and concisely, I figured I'd post this here.

How to create a content field that only accepts CiviCRM contacts.

My Goal: I want to add a field to an existing content type ("Resources") that autofills CiviCRM Contacts who are members of a specific CiviCRM group ("TVVRC Researcher").

Example of Use: Pat Smith is a CiviCRM Contact who's in the TVVRC Researcher group. I'm creating a new Resource, I start typing  "pat" in the "TVVRC Researcher" field, and it autofills, "Pat Smith."

Assumptions: You're running CiviCRM 4.5.6 and Drupal 7 and you have Views working correctly.

How to Set it Up:
1) Download, install, and enable the CiviCRM Entity module. https://www.drupal.org/project/civicrm_entity (See attached image.)
2) Create a view that returns exactly the results you want to display in your content's form field.
3) Add an Entity Reference to the view you just created. When you check to see if it returns the results you want, you'll see the following error: "Display "Entity Reference" needs a selected search field to work properly. See the settings for the Entity Reference list format."
4) Go to the "Format" section of the view and click on "Settings" for Entity Reference list. Put a check mark next to the Search Field(s) you want the autocomplete to search when you type in your content's form field. I like to use the display name since it contains the first and last names of the contact. Save your changes. Save your view. (See attached image.)
5) Go to Structure > Content Types > {The content type you want to add a field to.} > Manage Fields. Add a new field of type Entity Reference and form element Autocomplete. Label your field; machine name should auto-populate. Click Save. Drupal will bring you to the field settings page for the field you just created. (See attached image.)
6) Set Target Type to "CiviCRM civi_crm_contact" – Set Mode to "Views: Filter by an entity reference view" – Set View Used to Select the Entities to the entity reference view you created in Steps 3 and 4. Keep "View Arguments" empty. Save your work. Drupal will take you to the Edit page for this field. (See attached image.)
7) Enter your general field settings (Help text, number of values, etc.). Save your work. Drupal will take you to the Manage Fields page for your content type.
8) Move your new field to where you want it to appear on the create/edit form for your content type. Save your work.
9) Create a new instance of the content type your new field is attached to. Bask in the glory of what you've created. Congratulations! (See attached image.)

I hope this helps other people save time where I spent hours stumbling and fumbling. Enjoy!
« Last Edit: March 27, 2015, 08:01:20 am by texvet_webmaster »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: How to create a Drupal content field that only accepts CiviCRM contacts.
February 17, 2015, 08:55:37 am
Awesome writeup. Nice one :)

BTW have you joined the proposed StackExchange site yet? This would be a great thing to post there as soon as it launches. 87%! We just need a few more people to commit and it'll be party time there too :)
Try asking your question on the new CiviCRM help site.

texvet_webmaster

  • I’m new here
  • *
  • Posts: 26
  • Karma: 3
    • The TexVet Initiative
  • CiviCRM version: 4.5.6
  • CMS version: Drupal 7.34
  • MySQL version: 5.5.38
  • PHP version: 5.3.20
Re: How to create a Drupal content field that only accepts CiviCRM contacts.
February 17, 2015, 09:05:19 am
Thanks for the compliment. I sincerely hope it saves lots of Drupal/CiviCRM users time in the future.

"...have you joined the proposed StackExchange site yet?"

Just did. Woot!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: How to create a Drupal content field that only accepts CiviCRM contacts.
February 17, 2015, 11:10:04 am
Quote
Just did. Woot!
Awesome! Want to make your vote really count? That 87% represents the number of people who have committed AND have at least 200 rep on another SE site.
Ask or answer a handful of questions on drupal answers (it really doesn't take that much to get to 200) and you'll put us closer to the goal. With only 13% left to go, every individual makes a huge difference!
In fact, since your post here directly relates to Drupal, you could ask your question and then answer it yourself (this is allowed and even encouraged form of knowledge sharing on SE) for some free points!
Try asking your question on the new CiviCRM help site.

texvet_webmaster

  • I’m new here
  • *
  • Posts: 26
  • Karma: 3
    • The TexVet Initiative
  • CiviCRM version: 4.5.6
  • CMS version: Drupal 7.34
  • MySQL version: 5.5.38
  • PHP version: 5.3.20
Re: How to create a Drupal content field that only accepts CiviCRM contacts.
February 17, 2015, 11:25:29 am
Thanks for the tip. Amusingly, I have a ton of cred under a different account on their board game SE site. I like to keep my work and personal life separate, so it's a shame to let that SE cred go to waste for this purpose but... I'll do what I can. =)

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: How to create a Drupal content field that only accepts CiviCRM contacts.
February 17, 2015, 05:06:30 pm
Would be awesome to have your gaming persona sign up for the civi SE site just to help the beta launch, then you could switch back to your work persona afterwards :)
Try asking your question on the new CiviCRM help site.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: How to create a Drupal content field that only accepts CiviCRM contacts.
March 27, 2015, 05:26:55 am
Nice write-up!  Thanks texvet.

I'm trying to wrap my head around the CiviCRM Entity module and it's use case.

I'm having trouble finding any thorough resources like this one for it, but have a feeling I could really use it.

I've read and reread the https://civicrm.org/blogs/jackrabbithanna/drupalcivicrm-integration-civicrm-entity-and-webform-civicrm.  But I think I need one without Webform thrown in there.

Are there any other examples that are out there that anyone is aware of?

Thanks.
« Last Edit: March 27, 2015, 07:05:16 am by pmoz »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • How to create a Drupal content field that only accepts CiviCRM contacts.

This forum was archived on 2017-11-26.