This code goes into node_images.views.inc, and it's 100% re-written from scratch, because the current plugin is seriously broken.

HTH

// $Id: node_images.views.inc,v 1.3 2007/02/03 01:28:22 stefano73 Exp $

/**
 * @file
 * Views API hook implementations for the node_images module.
 */

function node_images_views_tables() {
  $tables['node_images'] = array(
    'name' => 'node_images',
    'join' => array(
      'left' => array(
        'table' => 'node',
        'field' => 'nid',
      ),
      'right' => array(
        'field' => 'nid'
      ),
    ),
    'fields' => array(
      'all_images' => array(
        'name' => t('Node Images: Display node images'),
        'notafield' => true,
        'query_handler' => 'views_query_handler_node_images',
        'handler' => array(
          'views_handler_node_images' => t('All images'),
        ),
        'option' => array(
          '#type' => 'select',
          '#options' => array(
            'thumbs' => t('Thumbnails'),
            'fullsize' => t('Full size images'),
          )),
        'sortable' => false,
        'help' => t('Display all node images in one field.'),
      ),
    ),
    'filters' => array(
      'nid' => array(
        'name' => t('Node images: Has node images'),
        'operator' => array('=' => t('Exists')),
        'list' => 'views_handler_operator_yesno',
        'list-type' => 'select',
        'handler' => '_node_images_handler_images_exist',
        'help' => t('Filter whether the node has node images.'),
      ),
    ),
    );
  return $tables;
}

function views_query_handler_node_images($field, $fieldinfo, &$query) {
  $query->add_field('nid', 'node');
}

/**
 * Handler for displaying all images of a node
 */
function views_handler_node_images($fieldinfo, $fielddata, $value, $data) {
  if ($listed) {
    $and = " AND list = 1";
  }

  $node = node_load(array('nid' => $data->nid));
  $result = db_query("SELECT ni.* FROM {node_images} ni INNER JOIN {node} n ON n.nid = ni.nid WHERE ni.nid = %d $and", $data->nid);
  while ($object = db_fetch_object($result)) {
    $node->node_images[$object->id] = $object;
  }
  return theme('node_images_view', $node, TRUE, FALSE, $fielddata['options']);
}

/**
 * Views handler for filtering
 */
function node_images_handler_images_exist($op, $filter, $filterdata, &$query) {
  switch ($op) {
    case 'handler':
      $query->ensure_table('node_images');
      if ($filter['value']) {
        $query->add_where('node_images.id');
      }
      else {
        $query->add_where('ISNULL(node_images.id)');
      }
    break;
  }
}
CommentFileSizeAuthor
#4 node_images.views_.inc_.patch6.87 KBgreg.harvey

Comments

mariano.barcia’s picture

Ups, there is a typo above, in the filter handler. The line

'handler' => '_node_images_handler_images_exist',

should be

'handler' => 'node_images_handler_images_exist',

(without the underscore prefix)
HTH

marcoBauli’s picture

mariano: could you please explain what does "the current plugin is seriously broken" mean? What does not work? cheers

mariano.barcia’s picture

marco,
From what I can recall, nothing worked, so it was useless.
HTH!

greg.harvey’s picture

Version: 4.7.x-2.x-dev » 5.x-1.x-dev
StatusFileSize
new6.87 KB

This worked fine for me. I added an extra field option called "lightest_image" to just show the image at the top of the available images too. Patch attached.