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) »
  • Drupal 7 views and custom file fields
Pages: [1]

Author Topic: Drupal 7 views and custom file fields  (Read 3387 times)

mattkevan

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
  • CiviCRM version: 4.02
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5
Drupal 7 views and custom file fields
June 24, 2011, 09:28:21 am
Hi, I'm trying to create a view of individuals that displays a 'Biography' and 'Photo' custom field for each in an unformatted list.

The biography is a note field so that works fine, however the photo is a file field and I can't get it to display properly.

I want to format the image using imagecache, but there doesn't seem to be the option to choose the preset when configuring the field display in Views. All I get is the file ID.

Is there a way of making it display the image? It doesn't even need to use imagecache if that's a problem - I just want a way of displaying the image.

Better still, a way of choosing the display like with the Drupal file field would be great - eg Display as imagecache image, as link to file, as data etc.

I'm using CiviCRM 4.02 and Drupal 7 with Views 3

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Drupal 7 views and custom file fields
June 24, 2011, 01:12:38 pm
Matt,

the quick answer is no.  CiviCRM does not have image handling like Drupal so no imagecache and no rendering images in Views.   THough you could try and write patch for the views integration to leverage imagecache :)

Sorry
http://www.rootyhollow.com

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Drupal 7 views and custom file fields
June 25, 2011, 01:49:59 pm
The other option would be to customize the template file for that field and use the API to find the correct file reference for the image.
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.

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: Drupal 7 views and custom file fields
June 27, 2011, 06:34:45 am
Two other options,

1.) Upload the image in Drupal to the user account and use Views relationships to create a relationship to the Drupal user account and display the Drupal user account image in your view.

2.) Views allows you to re-write the HTML for a field you may be able to write the file location into the href of an <a> tag with the tokens provided by views.
http://www.rootyhollow.com

GinkgoFJG

  • I post frequently
  • ***
  • Posts: 135
  • Karma: 4
    • Ginkgo Street Labs
Re: Drupal 7 views and custom file fields
July 28, 2011, 01:23:40 pm
I know this thread is a little old, but I just did something like this myself.  I'm preparing a fundraising campaign that will make heavy use of Personal Campaign Pages, and I wanted to apply an imagecache effect to images uploaded by end-users.  To do this, I had to override CRM/Contribute/Page/PCPInfo.php.

The original image-related code looked like this:
Code: [Select]
<?php
        
if ( $file_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $this->_id , 'file_id', 'entity_id') ) {
            
$image = '<img src="'.CRM_Utils_System::url( 'civicrm/file', 
                                                         
"reset=1&id=$file_id&eid={$this->_id}" ) . '" />';
            
$this->assign('image', $image);
        }
?>


My modified code looks like this:
Code: [Select]
<?php
        
if ( $file_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $this->_id , 'file_id', 'entity_id') ) {
            
$params = array(
              
'file_id' => $file_id
            
);

            if (
$image_path = helper_get_file_path($params)) {
              
$image = theme('imagecache', 'pcp', $image_path );
              
$this->assign('image', $image);
            }
        }

// helper function
function helper_get_file_path(array $params) {

  
$file_id = NULL;
  
$file_type_id = NULL;
  
extract($params, EXTR_IF_EXISTS);

  require_once(
'api/v2/File.php');

  
$filepath = NULL;
  
  if (
is_numeric($file_id)) {
    
$params = array(
      
'id' => $file_id,
      
'file_type_id' => $file_type_id
    
);
    
$file = civicrm_file_get($params);

    if (!
array_key_exists('is_error', $file)) {
      
$filepath = file_directory_path() . '/civicrm/custom/' . $file[$file_id]['uri'];
    }
  }
  
  return 
$filepath;
}
?>


Ways my code could be improved:
  • Use API v3 instead of v2.  My installation is still on CiviCRM 3.3, so API v3 is not available to me yet.
  • There's probably a variable or a function I can use to determine the proper upload directory for these files rather than hardcoding in '/civicrm/custom/'.  I got a little lazy  ::)
Are you a CiviVolunteer user? Join the CiviVolunteer 2.0 Matching Grant effort to help the project win $15,000 in grant funding.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Drupal 7 views and custom file fields

This forum was archived on 2017-11-26.