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) »
  • Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
Pages: [1] 2

Author Topic: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)  (Read 3746 times)

bouton

  • Guest
Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
October 26, 2011, 08:50:34 am
I am using Drupal 7.8 and CiviCRM 4.06.
I have uploaded/added an image to a contact (Organization) in CiviCRM. Data and image alll show up fine in civicrm.

also the API works
civicrm/ajax/rest?json=1&debug=1&version=3&entity=Contact&action=getsingle&contact_id=15&return=image_URL

When I then create a view I can add the field image_URL but it doesn't return anything. 
If I use the view SQL output and go directly to the database using phpmyadmin, I get a URL returned so I know it exists.

But it is just not coming out of the DB with the query.

In looking at civicrm/drupal/modules/views/civicrm/civicrm_handler_field_file.inc I see it points to api/v2/File.php rather than api/V3/File.php.

Any suggestions on how to progress
Thanks
« Last Edit: October 26, 2011, 09:06:30 am by bouton »

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
October 26, 2011, 09:15:11 am
I don't know, but hopefully our Views integration expert will chime in. But you could try to edit civicrm_handler_field_file.inc and see what happens. Try V3. Can't hurt anyhow. :)
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

bouton

  • Guest
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
October 27, 2011, 01:32:07 am
Tried changing it to V3, then cleared cache - nothing changed.
So - views integration experts - any suggestions?

bouton

  • Guest
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
October 27, 2011, 02:27:01 am
Updated to civicrm 4.0.7 - still have the problem and modules/civicrm/drupal/modules/views/civicrm/civicrm_handler_field_file.inc still includes require_once 'api/v2/File.php';

thanks

ekiczek

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
November 11, 2011, 11:15:15 am
I got this working and I'm not sure the bug you mention in modules/civicrm/drupal/modules/views/civicrm/civicrm_handler_field_file.inc is even related.

It appears the civicrm_contacts.image_URL contains a full URL. I think modules/civicrm/drupal/modules/views/civicrm/civicrm_handler_field_file.inc is a handler for fields that contain file ids, and I don't think that applies here.

I believe the main problem is that modules/civicrm/drupal/modules/views/civicrm.views.inc doesn't contain information about civicrm_contacts.image_URL. Without defining anything about civicrm_contacts.image_URL in the civicrm_views_data function, the field can be added to a view, and indeed the SQL query even works, but the output never gets to the final view display.

I modified civicrm_views_data to define $data['civicrm_contact']['image_url'] and to add image_url to $skipFields. I'm attaching the patch.

Once I did this, I saw *two* contact image URL fields in the field list. There is the default (with the help text "Image Url") and there is the new field I added (with the help text "Contact image URL"). Instead of picking the default, I picked the new one.

Now, running the view displays the URL of the image for that contact. You can modify the Rewrite Results in the Views UI, checking the box "Rewrite the output of this field" and changing the output to '<img src="[image_url]" />', and then the actual image should be displayed in the view.

Note: I think there is an issue between CiviCRM, Views and MySQL regarding case-sensitivity and field names. At first I tried my code with 'image_URL' instead of 'image_url', since the actual MySQL field name is image_URL. This overrode the default field in the view -- I only had one image URL field instead of two -- but the output was still blank.

My solution is clearly a hack and not very sustainable, but I wanted to share my findings so that we can get a working solution out-of-the-box in a future release.

bouton

  • Guest
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
November 15, 2011, 06:07:13 am
Thanks. That worked.

To make it a bit more sustainable I wrote my own little module which used hook_views_data_alter to make these changes.

I think this is the way to do it and make it so core updates won't overwrite the fixes.
Write a Drupal module and accompanying.info file.
In your module

/**
 * Implementation of hook_views_api().
 */
function yourmodulename_views_api() {
   return array(
      'api' => 3,
      'path' => drupal_get_path('module', 'yourmodulename') . '/views',
   );
}

then in dir yourmodulename/views/yourmodulename.views.inc
Code: [Select]
// put  changes to civicrm views data here

// http://views-help.doc.logrus.com/help/views/api
// alter civicrm.views.inc
function yourmodulename_views_data_alter(&$data) {

/* START CIVICRM FIXES */
// addlogo  image url
$data['civicrm_contact']['image_url'] = array(
'title'       => t('Contact logo URL'),
'help'        => t('URL for the logo image'),
'field'       => array(
'handler'     => 'views_handler_field',
)
);


Then for views I made a single field template views-view-field-your-field-name.tpl.php so I could show the image using an image style (imagecache preset in drupal 6 lingo). That template file had
Code: [Select]

// GET CIVICRM path
//print $output; 
if($row->your_image_url) {
$fileNameArray = explode("/",$row->your_image_url);
// get last item in array
$filename = end($fileNameArray);

$civicrmPath = "your/path/".$filename;
// Image styles in Drupal 7 are the equivalent of Imagecache presets in Drupal 6:
print theme('image_style',
array(
'style_name' => 'thumbnail',
'path' => $civicrmPath,
'attributes' => array(
'class' => 'someclassname'
) 
)
);
}

Thats got it working for me
Thanks
K

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
November 30, 2011, 08:06:31 pm
You two are my late night civi guardian angels.  I literally came across this problem 15 minutes ago and the magic bullet was presented to me courtesy of your previous labors.

You most likely saved me at least an entire night's worth of rolling up my sleeves and going deep.

Gold gentlemen, is what you so casually gifted me here tonight.

Thank you so very much.


DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
November 30, 2011, 10:06:04 pm
Hmmmm. Got greedy, ran into another hump.

Is there any way to hack the field so that instead of a being a URL, it is of type "image"?

I am trying to feed contact images into a views slideshow, but I can't seem to apply my imagecache resize profiles to the contact image url field
as I am using the following URL rewrite to get it to display.

<img src="[image_URL]" alt="[display_name]" />

« Last Edit: November 30, 2011, 10:09:39 pm by DerekL »

bouton

  • Guest
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
December 01, 2011, 01:23:19 am
The second part above that begins with   print theme('image_style',... will create the img html using the preset you give it in Drupal 7. Not sure about the slideshow - can you create just a single field template file rather that re-write the url? Good luck.

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
December 01, 2011, 02:53:46 pm
I'm having some trouble getting this to work.
I can confirm my template file is getting called in the view, but nothing displays for the field output.

I think I'm failing with this: "$row->your_image_url" what are the details on this piece?

I'm using this currently:

Code: [Select]
<?php
// GET CIVICRM path
 
print 'confirm we have the right template file';
//if($row->image_url) { 
 
   
$fileNameArray = explode("/",$row->image_url);
   
// get last item in array
   
$filename = end($fileNameArray);
      
   
$civipath = drupal_get_path('module', 'civicrm');
   
$civicrmPath = $civipath.'/custom/'.$filename;      
   
// Image styles in Drupal 7 are the equivalent of Imagecache presets in Drupal 6:
   
print theme('image_style',
      array(
         
'style_name' => 'thumbnail',
         
'path' => $civicrmPath ,
         
'attributes' => array(
         
'class' => 'someclassname'
         
) 
      )
   );

//}

?>

And even without the bool involved, nothing displays...

When I try and print $row->image_url, nothing displays.

 print 'confirm we have the right template file'; does work though.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
December 01, 2011, 03:00:14 pm
Use

Code: [Select]
echo '<pre>';
print_r($row);
echo '</pre>';

To see what is in $row.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
December 01, 2011, 03:18:47 pm
Nice! That's a keeper, thanks!

Here a row:

stdClass Object
(
    [id] => 7
    [civicrm_contact_image_url] => http://localhost/sites/default/files/civicrm/custom/bradesco_a2b2c3c8151ad36bbdcb99caf38887c8.png
)



Ok. I've got it to the point where I can do this: 
Code: [Select]
echo '<img src="'.$civicrmPath.'">';
and get an image to display.

When I use firebug to look at the <IMG> that's being built by views I see nothing less than:

<img class="someclassname" alt="" src="http://styles/thumbnail/http/localhost/sites/default/files/civicrm/custom/bradesco_a2b2c3c8151ad36bbdcb99caf38887c8.png" typeof="foaf:Image">

Who what where when did that "http://styles/thumbnail/" get in there?


« Last Edit: December 01, 2011, 04:19:38 pm by DerekL »

bouton

  • Guest
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
December 02, 2011, 02:41:50 am
My mistake - I was not very clear in my example. Its not the cvipath you want but the drupal default files folder. Is this clearer?
civiPath is not really the path to the civi image - it is the path to your /site/default/files/imagestorehere directory

I had to get the filename then add it onto the path I wanted
so this is more accurate
Code: [Select]
if($row->your_image_url) {
$fileNameArray = explode("/",$row->your_image_url);
// get last item in array
$filename = end($fileNameArray);
// set path to your drupal default files civicrm directory
$drupalDefaultPath = "sites/default/files/civicrm/custom/".$filename;
// Image styles in Drupal 7 are the equivalent of Imagecache presets in Drupal 6:
print theme('image_style',
array(
'style_name' => 'thumbnail',
'path' => $drupalDefaultPath ,
'attributes' => array(
'class' => 'someclassname'
) 
)
);
}

DerekL

  • I post frequently
  • ***
  • Posts: 132
  • Karma: 1
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.54
  • PHP version: 5.2.17
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
December 02, 2011, 09:05:26 am
Aha!

It works!

I went over to the imagecache documentation as I saw imagecache was making all sorts of crazy directory nests inside my sites/default/files folder.

According to the docs, $path is: The path of the image file relative to the Drupal files directory. This function does not work with images outside the files directory nor with remotely hosted images.

As soon as I replaced my :  /site/default/files/civicrm/custom

with : /civicrm/custom

Things worked.

Thank you again for your help!

Alex Sondy

  • I’m new here
  • *
  • Posts: 21
  • Karma: 0
  • CiviCRM version: 4.0.7
  • CMS version: Drupal 7.2
  • MySQL version: 5.0.7
  • PHP version: 5.3.5
Re: Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)
January 05, 2012, 09:07:05 am
Hello guys,

since Civi doesn't support ContactImage resizing out of the box, I want to place a views module with the contact image on the summary page.

Since you guys seem to have solved the issue, but went a little back and forth - would you mind to wrap up whats necessary to get views to pull the contact image as the type image, so image cache can be applied?

Thank you very much in advance!

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Views CiviCRM->Contacts image_URL returns nothing (also a bug in handler)

This forum was archived on 2017-11-26.