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) »
  • Custom data image, Drupal Views, Thumbnails?
Pages: 1 ... 4 5 [6] 7

Author Topic: Custom data image, Drupal Views, Thumbnails?  (Read 31189 times)

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:14:36 am
Quote from: lentilsoup on March 12, 2010, 11:12:07 am
And how does that line read now?

Code: [Select]
$old_path = $root . '/' . file_directory_path() . '/civicrm/custom' . $filename;
« Last Edit: March 12, 2010, 11:16:07 am by fm »

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:19:49 am
That's not how it read before?

Anyway, for some reason $filename is empty.  It looks like your version of CiviCRM is wrapping the results of crm_get_file() in an extra array.

Cut out that if/else block, and replace:

Code: [Select]
        // get the file details
       $file = crm_get_file(array('id'=>$id));
$filename = $file['uri'];
with:

Code: [Select]
        // get the file details
       $files = crm_get_file(array('id'=>$id));
       $file = array_shift($files);
$filename = $file['uri'];

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:28:09 am
It is now outputting the text: 'found file: ~/sites/<multi-site name>/files/civicrm/custom/72_dpi_Bosc_on_Box_edited_1_f3cf598b364fe47ea155995eddd67e49.jpg'

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:30:53 am
Please remove the if/else block with the found file / cannot find file die() statements.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:31:26 am
I just deleted the following from template.php: '   if(file_exists($old_path)) { die('found file: ' . $old_path); }
else { die('could not find file: ' . $old_path); }'


And deleted from the views theme file: echo $image_uri;

It seems to be working now. Hooray!

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:34:15 am
Now, if I want to set a different image dimension, do I do it at the end of the line below, replacing the 200 and 200?

function get_civicrm_image($id, $dimensions=array(200,200)) {

Update: I just tested that and the answer is apparently, "yes."

Yeah!
THANK YOU!

lentilsoup rocks!
« Last Edit: March 12, 2010, 11:39:38 am by fm »

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:43:47 am
Now. How do I link the image to its associated event page?

Hehe!

You have no idea how happy you've made me. Yesterday was the worst day I've had in years; today is looking up. :)

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:47:41 am
 8)

Glad you got it working!

For the reference of future visitors to the thread: the original code will work, provided you're putting it in the correct files, but you may have to adapt the paths in get_civicrm_image() if your installation either uses a non-standard upload path for CiviCRM or is installed somewhere other than the domain root.


lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 11:49:57 am
Quote from: fm on March 12, 2010, 11:43:47 am
Now. How do I link the image to its associated event page?

Make sure the event ID is one of the fields included in your view, and try

Code: [Select]
$event_url = url('civicrm/event/info') . '?id=' . $fields['id']->content;

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 01:51:49 pm
okay, I added the Event ID to the view, and I've got the following in the views theme file:

Code: [Select]
<a href="<?php $event_url = url('civicrm/event/info') . '?id=' . $fields['id']->content; ?>"><?php $image_uri = url(get_civicrm_image($fields['image_1']->content)); ?>
<img src="<?php echo $image_uri; ?>" /></a>

The image is linked, but only to the front page.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 02:57:18 pm
THe code I gave you just assigns the URL to a variable.  It doesn't output the URL.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 03:04:46 pm
Oh, so do I put that in the template.php file and then call the variable from the views theme file?

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 03:10:57 pm
No, you leave it in the views theme file, you just need to add an echo or print statement. 

I strongly recommend that you spend an hour or two learning the very basics of PHP.  It'll save you a lot of time in the long run.  Try this one.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 12, 2010, 03:31:01 pm
That worked. Thanks.

I had already called it with ah echo statement, so I was halfway there.

Yes, I need to learn the basics of php, and I will give it another shot (I've tried before). I've never been good with learning new languages -- human or computer. I possess no aptitude for it. However, there is something to be said for perserverance and I will apply myself with that in mind.

Again, thank you for your help. You have the patience of a saint and the coding skills of a ninja.
« Last Edit: March 12, 2010, 03:37:47 pm by fm »

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
December 04, 2010, 07:40:52 pm
The code to display custom images seems to conflict with something in CiviCRM 3.3.0. Upon upgrade the page containing the display code returned an error as follows:

Fatal error: require_once() [function.require]: Failed opening required 'api/File.php' (include_path='.:~/sites/all/modules/civicrm:~/sites/all/modules/civicrm/packages:.:/usr/lib/php:/usr/local/lib/php') in ~/sites/all/themes/blueprint/[sub-theme]/template.php on line 157

Commenting out the code below allows the page to display again, minus the image. Any tips on how I can adjust the code to restore the image display?

Code: [Select]
$image_uri = url(get_civicrm_image($fields['image_2']->content));

Pages: 1 ... 4 5 [6] 7
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Custom data image, Drupal Views, Thumbnails?

This forum was archived on 2017-11-26.