I've added a rownumber field to a view and the number produced is as expected for standard display styles (e.g. unformatted, list, table).

However, when used as in an OpenLayers Label, the values are rownumber + total number of rows, e.g. in a list they're "1,2,3", but in the OpenLayers map they're "4,5,6".

I think this is due to OpenLayers init-ing the handler once, but somehow iterating over it twice for the same record (ref: $this->rownumbers in views_customfield/includes/views_customfield_handler_field_rownumber.inc)

I'm not sue if the problem is with OpenLayers or Views Custom Field (or even just my config) but, whilst I investigate further, I'm posting here:

  • in case someone else has/will encounter it,
  • because it might be the same problem as #916406: Conflict with popup table?, and
  • I have a hunch that VCF should reset $this->rownumbers somewhere

Comments

Dave-B’s picture

By adding some echo statements I've found that calls to advanced_render() [0] from theme_views_view_field() [1] have correct rownumbers, but subsequent calls to advanced_render() by map_features() [2] add rownumber the the total last rownumber produced by theme_views_view_field()

I presume that the rownumbers property should be reset after theme_views_view_field() has finished with it...

[0] advanced_render() in sites/all/modules/views/handlers/views_handler_field.inc
[1] theme_views_view_field() in sites/all/modules/views/theme/theme.inc
[2] map_features() in sites/all/modules/openlayers/modules/openlayers_views/views/openlayers_views_style_data.inc

Dave-B’s picture

I've got the result I want, by reseting the rownumbers variable in the render() function of views_customfield/includes/views_customfield_handler_field_rownumber.inc, from:

  function render($values) {
    if ($this->view->pager['use_pager']) {
      return ++$this->rownumbers + ($this->view->pager['current_page'] * $this->view->pager['items_per_page']) + $this->view->pager['offset'];
    }else {
      return ++$this->rownumbers;
    }
  }

...to:

  function render($values) {
    if(!isset($this->firstid)) {
        $this->firstid = $values->node_node_data_field_sites_nid;
    } else if ($this->firstid == $values->node_node_data_field_sites_nid) {
        // Repeated step - probably a duplicate iteration, so reset number
        $this->rownumbers = 0;
    }
    if ($this->view->pager['use_pager']) {
      return ++$this->rownumbers + ($this->view->pager['current_page'] * $this->view->pager['items_per_page']) + $this->view->pager['offset'];
    }else {
      return ++$this->rownumbers;
    }
  }

(Of course, I probably ought to put that in a custom module, rather than editing the VCF code.)

This is a total hack, as I can't fathom how/where/why the render() code is being called in different ways, so it uses the details of the specific field I'm interested in.