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 Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Contact Reference fields as links
Pages: [1]

Author Topic: Contact Reference fields as links  (Read 774 times)

idmacdonald

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 1
Contact Reference fields as links
July 28, 2010, 04:40:54 am
Hi,

I am using Contact Reference custom fields to keep track of various links between contacts in a project I'm working on. These are working well. However, when a Contact Reference field is displayed on a contact's summary page, I think it would be nice if the contact name displayed could also be a link to that contact record.

I suppose that permissions issues might have to be taken into account here, in terms of whether the current user has permission to view said contact record. But it seems logical that when a contact reference field is displayed, it is displayed as a link.

I am willing to work on this (though I'm not so certain about the permissions issues), if someone could point me in the right direction. I've looked around CRM/Core/BAO/CustomField.php, but I can't quite see where the Contact ID is changed into the Display Name for viewing a Contact Reference field.

Any suggestions would be appreciated.

Thanks,
-Ian

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Contact Reference fields as links
July 28, 2010, 06:57:02 am
Ian :

You might wanna have a look at the patch for having a link instead of just the contact name.
However you should take care of the permission for editing the referenced contact.
Code: [Select]
Index: CRM/Core/BAO/CustomGroup.php
===================================================================
--- CRM/Core/BAO/CustomGroup.php (revision 28925)
+++ CRM/Core/BAO/CustomGroup.php (working copy)

@@ -1600,6 +1602,8 @@
         case 'ContactReference':
             if ( CRM_Utils_Array::value( 'data', $values ) ){
                 $retValue = CRM_Core_DAO::getFieldValue( 'CRM_Contact_DAO_Contact', $values['data'], 'display_name' );
+                $url = CRM_Utils_System::url('civicrm/contact/view',"reset=1&cid={$values['data']}");
+                $retValue = "<a href={$url}>$retValue</a>";
             }
             break;

HTH
-Yashodha
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

idmacdonald

  • I post occasionally
  • **
  • Posts: 69
  • Karma: 1
Re: Contact Reference fields as links
July 28, 2010, 08:01:21 am
Hi Yashodha,

That works! Thanks very much for the suggestion, I was looking in the wrong place for the relevant code. Might this be a feature to be included in a future version? I guess in that case, it would be good to do the permissions checking as well, though that's not so important to me at the moment.

Shall I enter it into Jira?

Many thanks,
-Ian


Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Contact Reference fields as links
July 28, 2010, 02:32:05 pm
Ian - Yes, would be good to include this in 3.2.1 with the permission check. Wanna take a shot at filing an issue with a patch for it? You can use this function to check if logged in user has VIEW permission on the contact (and only make it a link if they do):

CRM_Contact_BAO_Contact_Permission::allow( $contactId, CRM_Core_Permission::VIEW)
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Contact Reference fields as links

This forum was archived on 2017-11-26.