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) »
  • bug -- contact_type shows as blank in views
Pages: [1]

Author Topic: bug -- contact_type shows as blank in views  (Read 434 times)

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
bug -- contact_type shows as blank in views
May 30, 2014, 11:10:42 am
When I create a very simple view based on CiviCRM Contacts and show only the Contact ID and contact_type the contact type looks to be blank like this:

Contact ID: 1
Contact Type:
Contact ID: 11
Contact Type:

I can verify that on both my live and demo sites using civi 4.2.6  I can't test it on demo since I can't create views there.

I hunted around and in civicrm.views.inc on line 170+ I see

 function civicrm_views_add_fields(&$fields, &$data, $tableName, &$skipFields = NULL) {
   foreach ($fields as $name => $value) {
    // Only add fields not in $data or $skipFields and has a ['title']
    if (isset($value['custom_field_id']) ||
      CRM_Utils_Array::value($name, $skipFields) ||
      CRM_Utils_Array::value($name, $data) ||
      !isset($value['title']) ||
      (isset($value['where']) &&
        substr($value['where'], 0, strlen($tableName) + 1) != "{$tableName}."
      )
    ) {
      continue;
    }

If I remove CRM_Utils_Array::value($name, $data) || from that condition then civicrm_type begins to display the contact_type as I would expect like this:

Contact ID: 1
Contact Type: Individual
Contact ID: 11
Contact Type: Individual

I'm sure that's not the right way to fix it, it's just a hint for someone else who might know how to do it properly.  I know for sure this isn't the right way to fix it because when I take that out it changes the way the contact_type filters work.  When "CRM_Utils_Array::value($name, $data) ||" is left in, when you filter by contact_type you are presented with the option to tick check boxes for the types you want, but after taking that line out, when you filter it looks like a free text field.   And worse, it breaks any views set up to filter on contact type the "normal" way with "CRM_Utils_Array::value($name, $data) ||" left in.

I know only enough about this to be dangerous.  Is there someone else with a better handle on views integration who could decide on a good fix for this, or give me a push in the right direction?

     

civicrmsav

  • I post frequently
  • ***
  • Posts: 121
  • Karma: 5
  • CiviCRM version: 4.2.6
  • CMS version: Drupal 7.x
Re: bug -- contact_type shows as blank in views
June 12, 2014, 08:51:28 am
I dug into this a little more, but don't have time to complete the effort.

In /civicrm/drupal/modules/views/components|civicrm.core.inc line  499+ is the definition of the contact_type field.

  // contact_type
  $data['civicrm_contact']['contact_type'] = array(
    // The item it appears as on the UI,
    'title' => t('Contact Type'),
    // The help that appears on the UI,
    'help' => t('Contact Type'),
    'field' => array(
      'handler' => 'civicrm_handler_filter_pseudo_constant',                                       <<<<<<<<<<<<<<<<<<<<<<<<<<
      'click sortable' => TRUE,
      'pseudo class' => t('CRM_Core_SelectValues'),
      'pseudo method' => t('contactType'),
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'filter' => array(
      'handler' => 'civicrm_handler_filter_pseudo_constant',
      'pseudo class' => t('CRM_Contact_BAO_ContactType'),
      'pseudo method' => t('basicTypePairs'),
    ),
  );


Changing the line marked with <<<<<<<<<<<<<<<<<<<<<<  to 'handler' => 'civicrm_handler_field' seems  to solve the problem, which suggests there's something wrong with how the pseudo_constant handler is handling contact_types.  I couldn't quickly see how to fix that.
     

kennedy

  • I post occasionally
  • **
  • Posts: 119
  • Karma: 5
  • CiviCRM version: 4.5.5
  • CMS version: Drupal
  • PHP version: 5.3.10
Re: bug -- contact_type shows as blank in views
June 12, 2014, 12:06:13 pm
seems to work fine on 4.4.3, see screen capture below. You may consider upgrading

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • bug -- contact_type shows as blank in views

This forum was archived on 2017-11-26.