Answers.Body: <p>So you can configure your Entityreference field to display the rendered entity, and you can choose a view mode.  You can configure multiple view modes for CiviCRM Contact entity, and selectively choose which fields to include.  I highly recommend enabling Display Suite, and enabling a Display Suite layout for your view mode, as you will get field formatters for CiviCRM properties.</p>
  
  <p>To access subsidiary entities from the contact display, you can add CiviCRM Entity Reference (CER) fields to the Contact entity...this field type is provided by a submodule of the CiviCRM Entity project, and called CiviCRM Entity Reference Field.</p>
  
  <p>You can target addresses, emails, websites, phones etc...by created a CER field for each entity. The CER acts as a "remote reference field".  By this I mean that it accesses the subsidary data in the civicrm database directly, and does not store a target_id value in Drupal field tables....</p>
  
  <p>To display say a contact's addresses, on the contact view page (or the rendered contact via an entityreference field on a node view page), you set the CER to display the rendered entity, and like the normal entityreference field type, you can choose a view mode...you can create multiple view modes for the Address entity, configure which fields display, and thus achieve your goal, solely with site building, no code required. </p>
  
  <p>The Website entity is now supported as well in latest -dev (3-26-2017) of CiviCRM Entity, and the process is the same as described for displaying addresses.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-26T17:44:14.810Z
Answers.LastActivityDate: 2017-03-26T17:44:14.810Z
Answers.UserDisplayName: jackrabbithanna
Answers.Body: <p>The website is a separate entity from the contact; so is the address data, though some of it is made available (for the primary address only) on the Contact entity.</p>
  
  <p>I know the Address entity is available; I don't think the Website entity is, but that's out of an abundance of caution; it's basically identical to the Phone entity, so you should just be able to edit civicrm_entity.module to patch it in.  If you use it and it works, don't forget to submit a patch upstream!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-19T17:39:53.713Z
Answers.LastActivityDate: 2016-03-19T17:39:53.713Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>Using a slightly different approach we have done this many times, if i understand, by building a Drupal View (CiviCRM Contacts based) to pull in the information using Contextual Filters to ensure the relevant data shows on the node. You can see examples if this <a href="https://europeangreens.eu/parties/green-party-england-and-wales" rel="nofollow">here</a>.</p>
  
  <p>Pretty much all the data other than the body and map are Civi data that either relate to the contact that was connected to the node via 'CiviCRM reference field'</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-20T04:01:26.127Z
Answers.LastActivityDate: 2016-03-20T04:01:26.127Z
Answers.UserDisplayName: petednz - fuzion
Answers.Body: <p>Perhaps you need is CiviFirst's awesome Drupal <a href="https://github.com/JohnFF/CiviCRM-Session-Tokens" rel="nofollow noreferrer">CiviCRM Session Tokens</a> module, which gives you access to Civi data about the logged in user. That can then be accessed either via the _SESSIONS variable, or through the tokens in blocks or field filters - both of which this module translates for you - , or anywhere else that you can use tokens. I haven't yet included the contact's web address, but it could be easily expanded to cover that.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-26T18:59:18.903Z
Answers.LastActivityDate: 2017-03-26T18:59:18.903Z
Answers.UserDisplayName: JohnFF
Body: <p>I use CiviCRM 4.6.14 with Drupal 7.43.  I have defined a Drupal content type with a field that contains a CiviCRM contact using the <code>civicrm_entity</code> module.</p>
  
  <p>When I render this content type, I want to access a few fields from the contact - namely, its name, website, and a Google map link (derived from its address or geocode or whatever's best).  In PHP, how can I access these fields from the <code>$content</code> object?  If I <code>var_dump($content)</code> I can see the name &amp; geocode, but not a full address (should I piece that together from component fields? seems error prone) and no website field at all.  </p>
  
  <p>If I do this by trial and error using <code>var_dump</code>, I'm going to end up with code like </p>
  
  <pre><code>print($content['field_venue']['#items'][0]['entity']-&gt;display_name);
  </code></pre>
  
  <p>which doesn't seem healthy.</p>
  
Tags: <drupal><civicrm-entity><fields>
Title: Access CiviCRM fields from Drupal entity
ThreadText: # Access CiviCRM fields from Drupal entity
  
  (Asked by: username_0 on 2016-03-19)
  
  I use CiviCRM 4.6.14 with Drupal 7.43. I have defined a Drupal content type with a field that contains a CiviCRM contact using the `civicrm_entity` module.
  
  When I render this content type, I want to access a few fields from the contact - namely, its name, website, and a Google map link (derived from its address or geocode or whatever's best). In PHP, how can I access these fields from the `$content` object? If I `var_dump($content)` I can see the name & geocode, but not a full address (should I piece that together from component fields? seems error prone) and no website field at all.
  
  If I do this by trial and error using `var_dump`, I'm going to end up with code like
  
  ```
  print($content['field_venue']['#items'][0]['entity']->display_name);
  
  ```
  
  which doesn't seem healthy.
  
  **Tags:** drupal, civicrm-entity, fields
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2017-03-26. Score: 2
  
  So you can configure your Entityreference field to display the rendered entity, and you can choose a view mode. You can configure multiple view modes for CiviCRM Contact entity, and selectively choose which fields to include. I highly recommend enabling Display Suite, and enabling a Display Suite layout for your view mode, as you will get field formatters for CiviCRM properties.
  
  To access subsidiary entities from the contact display, you can add CiviCRM Entity Reference (CER) fields to the Contact entity...this field type is provided by a submodule of the CiviCRM Entity project, and called CiviCRM Entity Reference Field.
  
  You can target addresses, emails, websites, phones etc...by created a CER field for each entity. The CER acts as a "remote reference field". By this I mean that it accesses the subsidary data in the civicrm database directly, and does not store a target\_id value in Drupal field tables....
  
  To display say a contact's addresses, on the contact view page (or the rendered contact via an entityreference field on a node view page), you set the CER to display the rendered entity, and like the normal entityreference field type, you can choose a view mode...you can create multiple view modes for the Address entity, configure which fields display, and thus achieve your goal, solely with site building, no code required.
  
  The Website entity is now supported as well in latest -dev (3-26-2017) of CiviCRM Entity, and the process is the same as described for displaying addresses.
  
  
  ---
  
  ### Answer by username_2 on 2016-03-19. Score: 2
  
  The website is a separate entity from the contact; so is the address data, though some of it is made available (for the primary address only) on the Contact entity.
  
  I know the Address entity is available; I don't think the Website entity is, but that's out of an abundance of caution; it's basically identical to the Phone entity, so you should just be able to edit civicrm\_entity.module to patch it in. If you use it and it works, don't forget to submit a patch upstream!
  
  
  ---
  
  ### Answer by username_3 on 2016-03-20. Score: 1
  
  Using a slightly different approach we have done this many times, if i understand, by building a Drupal View (CiviCRM Contacts based) to pull in the information using Contextual Filters to ensure the relevant data shows on the node. You can see examples if this [here](https://europeangreens.eu/parties/green-party-england-and-wales).
  
  Pretty much all the data other than the body and map are Civi data that either relate to the contact that was connected to the node via 'CiviCRM reference field'
  
  
  ---
  
  ### Answer by username_4 on 2017-03-26. Score: 0
  
  Perhaps you need is CiviFirst's awesome Drupal [CiviCRM Session Tokens](https://github.com/username_4/CiviCRM-Session-Tokens) module, which gives you access to Civi data about the logged in user. That can then be accessed either via the \_SESSIONS variable, or through the tokens in blocks or field filters - both of which this module translates for you - , or anywhere else that you can use tokens. I haven't yet included the contact's web address, but it could be easily expanded to cover that.
  
  
  ---
  
  