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 2 [3] 4 5 ... 7

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

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 09, 2010, 09:36:19 pm
Ah, I thought we were working in a views-view-fields template, not a views-view-field template.

try...

Code: [Select]
<pre><?php print_r(array_keys(get_defined_vars())); ?></pre>
Also, you're going to have to change your template name so that it only applies to the image field, not other fields (check the Template Information section of the view to figure out how to name it).

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 09, 2010, 09:58:12 pm
Will it be easier just to change the name of the template to conform to views-view-fields?

(My bad. Why would they use nomenclature that is so poorly differentiated? ... rhetorical Q.)

Edit: Nevermind, I've made the changes you requested above. I now get the following output in the block:

Code: [Select]
Array
(
    [0] => template_file
    [1] => variables
    [2] => template_files
    [3] => view
    [4] => field
    [5] => row
    [6] => zebra
    [7] => id
    [8] => directory
    [9] => is_admin
    [10] => is_front
    [11] => logged_in
    [12] => db_is_active
    [13] => user
    [14] => output
)
« Last Edit: March 10, 2010, 05:42:08 am by fm »

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 10, 2010, 09:49:43 am
I strongly recommend you read up a bit on view template files so that you can understand what your code is doing.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 01:48:34 pm
I appreciate your help, and I understand working with me may be frustrating. I am not a programmer; I am a guy trying my best to stand up a site for a non-profit organization with no budget. I do not have the ability to create original code, not even simple original code. My ability to program is limited to deconstructing existing code, then making substitutions based on educated guesses and pattern recognition.

I have a fundamental grasp of what the views template files do, and what each template's specific application is. I am very sorry if my mistaking "field" for "fields" has caused you consternation. I know the difference between the purpose of each of these templates, and it was my fault for allowing the small but important difference in template names to confuse me. It is just one letter off, but programming is exact and unforgiving.

Your assistance has been indispensable, and I greatly appreciate your time, consideration, and willingness to share your knowledge. Anyway, thank you for your help and I regret having wasted your time.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 01:51:54 pm
You haven't caused me any consternation, and I'm happy to help you figure out how to use the code I've posted.  I just don't have time to explain the difference between the effects of customizing the fields vs the field template.  Once you figure out which you'd like to customize, I'll walk you through actually getting the image to display.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 06:41:02 pm
Okay, I've read up on views template files. The theming the 'row style output' (fields) seems to be what I'm looking for. I've retraced some of the exercises you suggested earlier in the thread; particularly, I was able to generate on-screen output for ...

Code: [Select]
print_r($fields['image_1']->content);
The output replaces the entire page and is:

Code: [Select]
Array ( [1] => Array ( [id] => 1 [file_type_id] => [mime_type] => image/png [uri] => g3157_c759aef97cf4fa5a1bc2879959bfd1a5.png [document] => [description] => [upload_date] => 2010-02-23 11:50:12 ) )
The code, of course, includes your original code snippet for the views template.

fwiw, the views theme file is now titled "views-view-fields--civicrm-events--block-3.tpl" and it's been moved to the sub-theme folder. I've already typed nonsense into the template to ensure Drupal is recognizing the file -- it is.

Please let me know if there was something specific about the views templates you think I'd benefit from reading more about.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 06:53:24 pm
Hm, is this an image field that can have multiple images uploaded to it, or something of the sort?  Either that or you're using a later version of CiviCRM, and the Views integration code has changed...

Anyway, it looks like in this case the value you want to pass to get_civicrm_image() is $fields['image_1']->content[1]['id']. 

Although I'm concerned that since the outer array is not 0-indexed, that 1 is showing up because it's the ID of the particular image.  If that first 1 changes when you're looking at a different image (you may have to create a dummy event and add another image in order to test this hypothesis), then you'll need to instead use something like:

Code: [Select]
$image_ids = array_keys($fields['image_1']->content);
$image_uri = url(crm_get_file($image_ids[0]));

or...

Code: [Select]
$image_uris = array();
$image_ids = array_keys($fields['image_1']->content);
foreach($image_ids as $image_id) {
    $image_uris[] = url(crm_get_file($image_id));
}



fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 07:26:43 pm
CiviCRM 3.1 here. And the image field was added via CiviCRM>Administer>Customize>Custom Data. I don't seem to have the ability to upload more than one image to the field per record.

I added an image to another event record and the front page has changed to:

Code: [Select]
Array ( [2] => Array ( [id] => 2 [file_type_id] => [mime_type] => image/jpeg [uri] => 72_dpi_Bosc_on_Box_edited_1_f3cf598b364fe47ea155995eddd67e49.jpg [document] => [description] => [upload_date] => 2010-03-11 10:01:35 ) )
The first of those two replacement snippets throws the following error on a white page ...

Fatal error: Call to undefined function crm_get_file() in ~/sites/all/themes/blueprint/<sub-theme>/views-view-fields--civicrm-events--block-3.tpl.php on line 23

The second throws the following at the top of my regular front-page content ...

warning: array_keys() [function.array-keys]: The first argument should be an array in ~/sites/all/themes/blueprint/<sub-theme>/views-view-fields--civicrm-events--block-3.tpl.php on line 22.
warning: array_keys() [function.array-keys]: The first argument should be an array in ~/sites/all/themes/blueprint/<sub-theme>/views-view-fields--civicrm-events--block-3.tpl.php on line 22.
warning: array_keys() [function.array-keys]: The first argument should be an array in ~/sites/all/themes/blueprint/<sub-theme>/views-view-fields--civicrm-events--block-3.tpl.php on line 23.
warning: Invalid argument supplied for foreach() in ~/sites/all/themes/blueprint/<sub-theme>/views-view-fields--civicrm-events--block-3.tpl.php on line 24.
« Last Edit: March 11, 2010, 07:34:54 pm by fm »

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 07:30:54 pm
Can you confirm for me what the code is that's producing that output?  (the one starting with "Array([2] => Array(..."

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 07:32:53 pm
Code: [Select]
<?php
// $Id: views-view-fields.tpl.php,v 1.6 2008/09/24 22:48:21 merlinofchaos Exp $
/**
 * @file views-view-fields.tpl.php
 * Default simple view template to all the fields as a row.
 *
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */
?>

<?php $img_uri = url(get_civicrm_image($fields['image_1']->content, array(300, 200))); ?>
<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <<?php print $field->inline_html;?> class="views-field-<?php print $field->class; ?>">
    <?php if ($field->label): ?>
      <label class="views-label-<?php print $field->class; ?>">
        <?php print $field->label; ?>:
      </label>
    <?php endif; ?>
      <?php
      
// $field->element_type is either SPAN or DIV depending upon whether or not
      // the field is a 'block' element type or 'inline' element type.
      
?>

      <<?php print $field->element_type; ?> class="field-content"><?php print $field->content; ?></<?php print $field->element_type; ?>>
  </<?php print $field->inline_html;?>>
  <?php print_r($fields['image_1']->content); ?>
<?php endforeach; ?>

Specifically, the additions to the standard template are:

Code: [Select]
<?php $img_uri = url(get_civicrm_image($fields['image_1']->content, array(300, 200))); ?>
and

Code: [Select]
 <?php print_r($fields['image_1']->content); ?>
« Last Edit: March 11, 2010, 07:41:53 pm by fm »

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 07:43:23 pm
Doh, I called the wrong function.  Stupid mistake on my part.

Try this:

Code: [Select]
$image_ids = array_keys($fields['image_1']->content);
$image_uri = url(get_civicrm_image($image_ids[0]));

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 07:46:23 pm
I removed both the previous snippets and inserted your last snippet in where the first snippet was. The output was a white page with the following:

Code: [Select]
CRM_Core_Error Object ( [_errors] => Array ( [0] => Array ( [code] => 8000 [params] => Array ( [0] => ) [package] => CiviCRM [level] => Fatal [time] => 1268365444.03 [context] => Array ( [file] => ~/sites/all/modules/civicrm/CRM/Core/Error.php [line] => 417 [function] => createError [class] => CRM_Core_Error ) [message] => Required parameters missing. ) ) [_errorsByLevel] => Array ( [Fatal] => Array ( [0] => Array ( [code] => 8000 [params] => Array ( [0] => ) [package] => CiviCRM [level] => Fatal [time] => 1268365444.03 [context] => Array ( [file] => ~/sites/all/modules/civicrm/CRM/Core/Error.php [line] => 417 [function] => createError [class] => CRM_Core_Error ) [message] => Required parameters missing. ) ) ) [_package] => CiviCRM [_compat] => [_msgCallback] => Array ( [0] => CRM_Core_Error Object *RECURSION* [1] => getErrorMessage ) [_contextCallback] => Array ( [0] => CRM_Core_Error Object *RECURSION* [1] => getFileLine ) [_errorCallback] => Array ( ) [_logger] => Log_display Object ( [_lineFormat] => %3$s: %4$s
[_timeFormat] => %b %d %H:%M:%S [_opened] => [_id] => e2928f29db30e1fc7c8c7f024f83b91c [_ident] => [_priority] => 6 [_mask] => 255 [_listeners] => Array ( ) [_formatMap] => Array ( [%{timestamp}] => %1$s [%{ident}] => %2$s [%{priority}] => %3$s [%{message}] => %4$s [%{file}] => %5$s [%{line}] => %6$s [%{function}] => %7$s [%{class}] => %8$s [%\{] => %%{ ) ) [_errorMsgs] => Array ( ) )
[/code][/code]
« Last Edit: March 11, 2010, 07:47:56 pm by fm »

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 07:52:06 pm
Well, that is seriously not a helpful error message on CiviCRM's part.

Lessee...

Please confirm that the place you put that snippet was in the same file you excerpted above (the one starting with the big comment block).

Please also tell me what the output is of the following:

Code: [Select]
$image_ids = array_keys($fields['image_1']->content);
print_r($image_ids);

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 07:58:58 pm
Snippet Placement:

Code: [Select]
<?php
// $Id: views-view-fields.tpl.php,v 1.6 2008/09/24 22:48:21 merlinofchaos Exp $
/**
 * @file views-view-fields.tpl.php
 * Default simple view template to all the fields as a row.
 *
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */
?>

<?php $image_ids = array_keys($fields['image_1']->content); 
$image_uri = url(get_civicrm_image($image_ids[0])); ?>

<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <<?php print $field->inline_html;?> class="views-field-<?php print $field->class; ?>">
    <?php if ($field->label): ?>
      <label class="views-label-<?php print $field->class; ?>">
        <?php print $field->label; ?>:
      </label>
    <?php endif; ?>
      <?php
      
// $field->element_type is either SPAN or DIV depending upon whether or not
      // the field is a 'block' element type or 'inline' element type.
      
?>

      <<?php print $field->element_type; ?> class="field-content"><?php print $field->content; ?></<?php print $field->element_type; ?>>
  </<?php print $field->inline_html;?>>
<?php endforeach; ?>

That newest snippet (swapped for the above modification) returns the following at the top of the normal contents area:

warning: array_keys() [function.array-keys]: The first argument should be an array in ~/sites/all/themes/blueprint/<sub-theme>/views-view-fields--civicrm-events--block-3.tpl.php on line 22.
warning: array_keys() [function.array-keys]: The first argument should be an array in ~/sites/all/themes/blueprint/<sub-theme>/views-view-fields--civicrm-events--block-3.tpl.php on line 22.
warning: array_keys() [function.array-keys]: The first argument should be an array in ~/all/themes/blueprint/<sub-theme>/views-view-fields--civicrm-events--block-3.tpl.php on line 22.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 11, 2010, 08:06:20 pm
Honestly, this is making no sense whatsoever.

Code: [Select]
<?php
// $Id: views-view-fields.tpl.php,v 1.6 2008/09/24 22:48:21 merlinofchaos Exp $
/**
 * @file views-view-fields.tpl.php
 * Default simple view template to all the fields as a row.
 *
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */
?>

<pre><?php $test = $fields['image_1']->content; 
print_r($test);
print_r($fields['image_1']->raw);
 
?>
</pre>

What does that get you?

Pages: 1 2 [3] 4 5 ... 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.