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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • [Solved] Using api to pull display_name into Drupal node only partially works
Pages: [1]

Author Topic: [Solved] Using api to pull display_name into Drupal node only partially works  (Read 881 times)

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
[Solved] Using api to pull display_name into Drupal node only partially works
March 24, 2010, 01:57:06 pm
I wrote the following theme functions, drawing on Contact and Group API:
Code: [Select]
<?php
/* override_function to replace username with First and Last Name pulled from Civi. */
function discerning_node_submitted($node) {

  
civicrm_initialize();
  require_once(
'api/v2/Contact.php');
  require_once(
'api/v2/UFGroup.php');

  
$nodeAuthorID = $node->uid;
  
$nodeAuthorCiviID = civicrm_uf_match_id_get($nodeAuthorID);
  
  
$params = array(
                    
'contact_id'          => $nodeAuthorCiviID,
                    
'return.display_name' => 1,
                    );
  
$authorInfo = civicrm_contact_search( $params );


/*
  if ( civicrm_error ( $result ) ) {
      return $result['error_message'];
  } else {
      print_r( $result ); //It will print array of contacts with return property set ie. display name
  }
*/

  
  
return t('Authored by !username on @datetime',
    array(
      
'!username' => $authorInfo[$nodeAuthorCiviID]['display_name'],
      
'@datetime' => format_date($node->created),
    ));

}

If I call <drupal_path>/node/%, such as /node/60 I get what I want:
Quote
Authored by Shawn Duncan on Wed, 03/24/2010 - 4:21pm

But on summary pages such as /node or taxonomy/term/% I get an Civi Error:
Quote
   Sorry. A non-recoverable error has occurred.

    DB Error: no such field

    Return to home page.

Error Details:

Array
(
    [callback] => Array
        (
            
  • => CRM_Core_Error
  • [1] => handle
            )

        {code] => -19
        
[message] => DB Error: no such field
    [mode] => 16
    [debug_info] => SELECT contact_a.id as contact_id, contact_a.display_name  as `display_name`  FROM civicrm_contact contact_a WHERE  ( contact_a.id = Array )  LIMIT 0, 25  [nativecode=1054 ** Unknown column 'Array' in 'where clause']
    [type] => DB_Error
    [user_info] => SELECT contact_a.id as contact_id, contact_a.display_name  as `display_name`  FROM civicrm_contact contact_a WHERE  ( contact_a.id = Array )  LIMIT 0, 25  [nativecode=1054 ** Unknown column 'Array' in 'where clause']
    [to_string] => [db_error: message="DB Error: no such field" code=-19 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT contact_a.id as contact_id, contact_a.display_name  as `display_name`  FROM civicrm_contact contact_a WHERE  ( contact_a.id = Array )  LIMIT 0, 25  [nativecode=1054 ** Unknown column 'Array' in 'where clause']"]
)

Can anyone help me find my error?  Why does it work when viewing the node but not the teaser?
« Last Edit: March 25, 2010, 09:44:54 am by FatherShawn »
Lead Developer, C3 Design.
Twitter: @FatherShawn

FatherShawn

  • Ask me questions
  • ****
  • Posts: 372
  • Karma: 25
    • C3 Design
  • CiviCRM version: 4.2.11
  • CMS version: Drupal 7.23
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Re: [Solved] Using api to pull display_name into Drupal node only partially work
March 25, 2010, 09:48:34 am
No logic error in my code, just a lack of error checking.  I had sample content whose author had been deleted, searching on uid = 0 fails in the api!

Working through that led me to shift from theme_node_submitted to theme_username.  It now works and I've posted the code on the API Snippet Page.
Lead Developer, C3 Design.
Twitter: @FatherShawn

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • [Solved] Using api to pull display_name into Drupal node only partially works

This forum was archived on 2017-11-26.