Hi! I've embedded a view of images in a story node - actually the image_gallery view that comes bundled in the image module. I've used the following code which works in most cases:

    $view = views_get_view('image_gallery');
    $vout = $view->execute_display('items', array(NULL, $tid));

It works fine when there are 0 images in the gallery, and when there is more than 1 image. But if there is exactly 1 image, the image node is displayed and not the story node with the image gallery

So, the way I see it:
1. Is there any way in views of overriding the default views behaviour so it doesn't jump to the image node's page when it returns only 1 item?
2. If not, is there any way of getting a count of images returned by the view without actually using execute_display()? I can get the count of items with print_r(count($view->result)); but only after using execute_display and then it is too late and the single image node is displayed. So I guess I'm asking if there are any other methods exposed the $view class that will run the query without displaying the output?

Many thanks in advance!

Comments

dawehner’s picture

Are you really sure the display is called items? I guess it should be called default or something similar.

1) Can you please export the view, you didn't described how your view is described.
2) You can use pre_execute and execute. There nothing gets rendered.

badzilla’s picture

Sorry, yes, I was playing around with different values and left items in there. It should be default.

2. I had a look at execute but it only returns TRUE or FALSE. I need something that returns an array to the sql output.

However, I have found my own solution. I can determine how many images there are in the gallery by reading the term_node table with the taxonomy api call taxonomy_select_nodes() function.

I am still curious though - is it possible to say to views - "If the resultset form the view is 1 DON'T jump straight to the image node. Still display the gallery with just 1 image in it."

I've attached the image_gallery view

$view = new view;
$view->name = 'image_gallery';
$view->description = 'The default gallery of image nodes from Image gallery module.';
$view->tag = 'image_gallery';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'image_image' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'image_derivative' => 'thumbnail',
    'exclude' => 0,
    'id' => 'image_image',
    'table' => 'node',
    'field' => 'image_image',
    'relationship' => 'none',
  ),
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'title' => array(
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
  ),
  'changed' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'changed',
    'table' => 'node',
    'field' => 'changed',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'null' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'must_not_be' => 0,
    'id' => 'null',
    'table' => 'views',
    'field' => 'null',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => 'tid',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'image' => 0,
      'page' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
    ),
    'validate_argument_type' => 'tid',
    'user_argument_type' => '',
    'restrict_user_roles' => 0,
    'user_roles' => array(),
    'image_size' => array(
      '_original' => '_original',
      'thumbnail' => 'thumbnail',
      'preview' => 'preview',
    ),
    'validate_argument_php' => '',
  ),
  'tid' => array(
    'default_action' => 'empty',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '%2',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'numeric',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'reduce_duplicates' => 0,
    'set_breadcrumb' => 1,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'image' => 0,
      'page' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 1,
    ),
    'validate_argument_type' => 'tid',
    'user_argument_type' => 'uid',
    'restrict_user_roles' => 0,
    'user_roles' => array(),
    'image_size' => array(
      '_original' => '_original',
      'thumbnail' => 'thumbnail',
      'preview' => 'preview',
    ),
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'image' => 'image',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Image galleries');
$handler->override_option('empty', 'There are no images in this gallery.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 12);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'image_gallery');
$handler->override_option('style_options', array(
  'grouping' => '',
  'type' => 'ul',
));
$handler = $view->new_display('image_gallery', 'Gallery page', 'image_gallery_1');
$handler->override_option('path', 'image');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));
dawehner’s picture

Status: Active » Fixed

The display name should be image_gallery_1

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.