I'm using views_cycle.module which renders 'thumbnails' for the cycler using a field of your choice. There is a loop in the module's code that contains the line:

$vars['thumbs_data'] .= "<li class='{$classes}' >". $view->render_field($options['thumbnail_field'], $num) ."</li>";.

As of views-6.x-2.7, if the chosen field is the global counter, i.e. $options['thumbnail_field'] == 'counter', the return value is always the total number of rows rather than the current row, regardless of the value of $num in the above line.

To put it another way, if I am outputting 3 rows in my view, $view->render_field($options['thumbnail_field'], $num) always returns 3. The thumbnails render as "3 3 3" rather than "1 2 3."

I could be wrong but this seems like unintended behaviour from views.module rather than something that needs patching in views_cycle.module.

Comments

dawehner’s picture

Can you please try to use the dev version, i think there was something fixed there.

morbiD’s picture

Component: Miscellaneous » Code

Oh, I forgot to say, I already tried the dev version hoping it was fixed, and got the same problem but with the count decreased by 1.

So, in 6.x-2.6 my thumbnails read "1 2 3" as they should.
In 6.x-2.7 they read "3 3 3."
In the current 6.x-2.x-dev they read "2 2 2."

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Can you please export your view? Then i can have a look at

morbiD’s picture

Here you go:

$view = new view;
$view->name = 'featured_content';
$view->description = 'Featured content cycler';
$view->tag = '';
$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(
  'counter' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'counter_start' => '0',
    'exclude' => 1,
    'id' => 'counter',
    'table' => 'views',
    'field' => 'counter',
    'relationship' => 'none',
  ),
  'field_news_picture_fid' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'label_type' => 'none',
    'format' => 'Features_linked',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_news_picture_fid',
    'table' => 'node_data_field_news_picture',
    'field' => 'field_news_picture_fid',
    'relationship' => 'none',
  ),
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '<h3>[title]</h3>',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'teaser' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'teaser',
    'table' => 'node_revisions',
    'field' => 'teaser',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'field_feature_value_many_to_one' => array(
    'operator' => 'or',
    'value' => array(
      '1' => '1',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'field_feature_value_many_to_one',
    'table' => 'node_data_field_feature',
    'field' => 'field_feature_value_many_to_one',
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
  'picg' => array(
    'operator' => '=',
    'value' => '',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'picg',
    'table' => 'og_ancestry',
    'field' => 'picg',
    'relationship' => 'none',
  ),
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'group_news' => 'group_news',
    ),
    '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('use_ajax', TRUE);
$handler->override_option('use_pager', '0');
$handler->override_option('use_more', 0);
$handler->override_option('use_more_text', 'more...');
$handler->override_option('style_plugin', 'cycle');
$handler->override_option('style_options', array(
  'type' => 'ul',
  'skin' => 'sidelist_bottom',
  'thumbnail_field' => 'counter',
  'pager' => array(
    'event' => 'click',
  ),
  'params' => array(
    'fx' => 'fade',
    'timeout' => '10000',
  ),
  'skin_info' => array(
    'title' => 'Side list (bottom)',
    'pager_location' => 'after',
    'stylesheets' => array(
      '0' => 'views_cycle_sidelist_bottom.css',
    ),
    'module' => 'views_cycle',
    'path' => '',
  ),
));
$handler->override_option('row_options', array(
  'inline' => array(
    'title' => 'title',
    'teaser' => 'teaser',
  ),
  'separator' => '',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
dawehner’s picture

Project: Views (for Drupal 7) » Views cycle
Version: 6.x-2.7 » 6.x-1.x-dev
Status: Postponed (maintainer needs more info) » Active

I guess you should use the dev version of views_cycle see http://drupal.org/project/cvs/408888

Move to views_cycle issue queue

morbiD’s picture

Project: Views cycle » Views (for Drupal 7)
Version: 6.x-1.x-dev » 6.x-2.x-dev

Sorry. Please forgive me if I am misunderstanding the way the issues tracking system works, as I have never reported a bug before, but why move this to the views_cycle queue?

Both the global results counter field and the render_field() function are components of views. views_cycle merely makes a call to render_field() which works perfectly when passed any field name, except the global counter which stopped working with the latest release of views, when I believe a patch to views_handler_field_counter.inc was committed.

If the bug is in views, how will moving the bug report to views_cycle help fix it?

Also, I'm already using the latest dev version of views_cycle as suggested. Indeed, I notice the views_cycle CVS message: Switch from ->theme() to $view->render_field() in the preprocess function, per recommendation from merlinofchaos so it's not like views_cycle shouldn't be using render_field(). The combination of render_field('counter', $row) is just broken.

Do correct me if I'm looking at this the wrong way, of course.

morbiD’s picture

Title: views_handler_field_counter::render() ignores $values so $view->render_field('counter', $row) always returns last row count » render_field() returns incorrect value for global counter field

I see the root cause of this now. The render() function in views_handler_field_counter.inc does absolutely nothing with objects passed to it, so it is seemingly impossible to request the count for any specific row.

The count gets incremented when views builds each row, and once the last row has been built the count remains at that final value. Thus, other modules can only get the count for the last row.

morbiD’s picture

Title: render_field() returns incorrect value for global counter field » views_handler_field_counter::render() ignores $values so $view->render_field('counter', $row) always returns last row count
merlinofchaos’s picture

Title: render_field() returns incorrect value for global counter field » views_handler_field_counter::render() ignores $values so $view->render_field('counter', $row) always returns last row count
Status: Active » Closed (works as designed)

Note that as of Views 2.7 all the fields are now pre-rendered for the style, which is probably the problem here. The problem is that with this change, you're not rendering a field a second time, which is unnecessary.

The style can get its fields off of $fields = $this->rendered_fields which will get all of the fields that were rendered. This was necessary to make certain substitutions work.

Crell’s picture

Hm, someone forgot to tell me about that change in 2.7. :-) I've updated views_cycle to use ->rendered_fields, and I think it's working now (as of the latest dev). If not, please open an issue in the views_cycle queue.