aboutsummaryrefslogtreecommitdiff
path: root/includes/video_views_handler_field_image.inc
blob: fbbe905ef62093f8fbd2747b9923dc14e1e09179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
//$Id$
/**
* Implementation of hook_views_tables
*
* @return
*   array - Enables support in the video module for views integration
 * @author Glen Marianko Twitter@demoforum <glenm at demoforum dot com>
 * @todo
**/

/**
 * Field handler to display the video preview thumbnail
 *
 * @ingroup views_field_handlers
 */
class video_views_handler_field_image extends views_handler_field {
    /**
   * Define options available for this field.
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['img_type'] = array('default' => 'thumbnail');
    $options['disp_link'] = array('default' => TRUE);
    return $options;
  }

  /**
   * Build option configuration form.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    $form['img_type'] = array(
      '#title' => t('Show image as'),
      '#type' => 'select',
      '#options' => array(
        'thumbnail' => t('Thumbnail'),
        'preview' => t('Preview'),
        ),
      '#default_value' => $this->options['img_type'],
    );
    $form['disp_link'] = array(
      '#title' => t('Link image to video'),
      '#type' => 'checkbox',
      '#default_value' => $this->options['disp_link'],
    );

  }
/**
   * Render field output to the browser.
   */
  function render($values) {
    return _video_views_handler_field_image($values, $this->options['img_type'], $this->options['disp_link']);
  }
}
/**
* Handler to render the preview image associated with a video
**/
function _video_views_handler_field_image($values, $image_type, $linked) {
 if($values->node_type &&  $values->node_type != 'video') return NULL;
 $node = node_load($values->nid);
 $output = NULL;
 if($node->iid && $image = node_load($node->iid)) {
     $image_html = NULL;
     if($image != NULL && $image->type == 'image') {
        $image_html = image_display($image, $image_type, array('class' => 'video_image_teaser'));
        //Create a link with an image in it.
        $output .= ($linked ? l($image_html, "node/$values->nid", array('html' => TRUE)) : $image_html);
        $output .= '<br class="video_image_clear" />';
      }
 }
 return $output;
}