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 (Moderator: Donald Lobo) »
  • Customize contact profile look and feel (Drupal)
Pages: 1 [2]

Author Topic: Customize contact profile look and feel (Drupal)  (Read 4846 times)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Customize contact profile look and feel (Drupal)
October 16, 2010, 02:33:31 pm

danny:

1. can u please update and correct the wiki with regard to the profileFields documentation

2. u can either parse and extract the image URL from the value field OR use a civicrm hook to assign just the imageURL to the smarty template

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

dwatts3624

  • Guest
Re: Customize contact profile look and feel (Drupal)
October 16, 2010, 06:13:09 pm
I updated the following wiki page with these results:
http://wiki.civicrm.org/confluence/display/CRMDOC32/Customize+Built-in,+Profile,+Contribution+and+Event+Registration+Screens

I've been trying to make some headway on the image url issue.  As the CiviCRM hook approach seemed a bit over my head I've been trying to grab the src attribute with a regular expression but, apparently, am not familiar enough with Smarty to make that happen.

Any direction on either solutions?  For hooks, which hook should I use and where should I run it?  Does it need to be a module?  For parsing the src attribute, where would I drop to PHP function to pull out the result in Smarty?  Is there a way to parse it with regex inside Smarty like I've been trying to?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Customize contact profile look and feel (Drupal)
October 17, 2010, 07:20:36 am

the hooks are documented here:

http://wiki.civicrm.org/confluence/display/CRMDOC32/CiviCRM+hook+specification
http://en.flossmanuals.net/CiviCRM/DevelopIntro

You should be able to customize the tpl and do a fair amount with smarty (http://www.smarty.net/manual/en/). I dont now how easy/hard doing what you want is

lobo



A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

dwatts3624

  • Guest
Re: Customize contact profile look and feel (Drupal)
October 17, 2010, 10:23:35 am
I've been reading through these resources and don't think that's going to happen without examples close to what I'm trying to.  My programming skills are limited to taking what smarter people have done and modifying their work.  ;)

I did, however, begin looking through this article (which will definitely come in handy for future improvements):
http://wiki.civicrm.org/confluence/display/CRMDOC32/Smarty+interface

And I came up with this:
{crmAPI entity="contact" action="get" var="contactFields" contact_id=$contactId }

In my Smarty debug and by printing out {$contactFields|@print_r} I can see this is working but the $contactId variable is empty (which, I guess, makes sense) so it's printing out all the contacts rather than just the one respective to the user profile being viewed.

This seems like a suitable solution if I can grab the right ID since, in the contact array, "image_URL" is, in fact, the URL to the contact image and not the profile HTML produced from {$profileFields.image_URL}.

Any idea how I can get the user/contact ID of the drupal profile being viewed?

dwatts3624

  • Guest
Re: Customize contact profile look and feel (Drupal)
October 17, 2010, 11:54:24 am
I got it! :)

Thanks to these examples (http://svn.civicrm.org/civicrm/trunk/drupal/civitest.module.sample) and the contents of this thread.

I created a new Drupal module called "civicrm_hooks" and activated it in the modules screen.  The contents of that file are below.

Code: [Select]
<?php
function civicrm_hooks_civicrm_pageRun( &$page ) {
    
// You can assign variables to the template using:
    // $page->assign( 'varName', $varValue );
    // in your template, {$varName} will output the contents of $varValue
    // you should customize your template if doing so

$contactID = $page->getVar( '_id' );

if ( $page->getVar( '_name' ) != 'CRM_Profile_Page_Dynamic' ||
         
$page->getVar( '_gid' ) != 1 ||
         ! 
CRM_Utils_Rule::positiveInteger( $contactID ) ) {
        return;
    }

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

$params = array( 'contact_id' => $contactID );

$retrieved = &civicrm_contact_get( $params );

    
$page->assign( 'contactID', $contactID );
$page->assign( 'contactFields', $retrieved );
}
?>


In my Dynamic.tpl file, I'm calling {$contactFields.$contactID.image_URL} which gives me the contact image URL itself.

I guess I could have stepped into the array in my hook (since this is a bit redundant) or just grabbed the contact ID in the hook and used the Smarty civiAPI like I mentioned before.

Like I said before, I'm definitely not good at this stuff so if there's a more efficient or better way to do this let me know.

Thanks for all of your help!  Let me know if you'd like me to contribute this to any documentation.

Danny

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Customize contact profile look and feel (Drupal)

This forum was archived on 2017-11-26.