Grouping by CCK Date field does not work

mongolito404 - October 15, 2009 - 15:56
Project:Views
Version:6.x-2.6
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

Hi,

Using a modified calendar view (see http://ur1.ca/do3a), grouping by a CCK Date field does not work. What puzzled me is that on my dev. environment it works. It is probably not a bug but a configuration error somewhere.

Does anybody have any idea of where to look ?

PS: I attached a screenshot of the view style config.

AttachmentSize
view-group-date.png65.52 KB

#1

mongolito404 - October 21, 2009 - 09:26
Category:support request» bug report

After some crude debugging, it appears that on my production site (where groupin is not working), in views_plugin_style::render_grouping($records, $grouping_field), $this->view->field[$grouping_field]->theme($row) returns an empty string. It appears to do so until $this->row_plugin->render($row) in first invoked later in views_plugin_style::render().

For quick reference, here is the full code for the two functions from views_plugin_style.inc

<?php
 
/**
   * Render the display in this style.
   */
 
function render() {
    if (
$this->uses_row_plugin() && empty($this->row_plugin)) {
     
vpr('views_plugin_style_default: Missing row plugin');
      return;
    }

   
// Group the rows according to the grouping field, if specified.
   
$sets = $this->render_grouping($this->view->result, $this->options['grouping']);

   
// Render each group separately and concatenate.  Plugins may override this
    // method if they wish some other way of handling grouping.
   
$output = '';
    foreach (
$sets as $title => $records) {
      if (
$this->uses_row_plugin()) {
       
$rows = array();
        foreach (
$records as $label => $row) {
         
$rows[] = $this->row_plugin->render($row); /*! Until the first pass here, $this->view->field[$this->options['grouping']]->theme($row) returns '' */
       
}
      }
      else {
       
$rows = $records;
      }

     
$output .= theme($this->theme_functions(), $this->view, $this->options, $rows, $title);
    }
    return
$output;
  }

 
/**
   * Group records as needed for rendering.
   *
   * @param $records
   *   An array of records from the view to group.
   * @param $grouping_field
   *   The field id on which to group.  If empty, the result set will be given
   *   a single group with an empty string as a label.
   * @return
   *   The grouped record set.
   */
 
function render_grouping($records, $grouping_field = '') {
   
   
$sets = array();
    if (
$grouping_field) {
      foreach (
$records as $row) {
       
$grouping = '';
       
// Group on the rendered version of the field, not the raw.  That way,
        // we can control any special formatting of the grouping field through
        // the admin or theme layer or anywhere else we'd like.
       
if (isset($this->view->field[$grouping_field])) {
         
$grouping = $this->view->field[$grouping_field]->theme($row);
          if (
$this->view->field[$grouping_field]->options['label']) {
           
$grouping = $this->view->field[$grouping_field]->options['label'] . ': ' . $grouping;
          }
        }
       
$sets[$grouping][] = $row;
      }
    }
    else {
     
// Create a single group with an empty grouping field.
     
$sets[''] = $records;
    }
    return
$sets;
  }
?>

#2

mongolito404 - October 21, 2009 - 09:34
Category:bug report» support request

Sorry, this is probably not a bug in views... But I'm still lost and don't know exactly where to look.

#3

merlinofchaos - November 2, 2009 - 19:36
Status:active» fixed

Try the -dev version, which has had significant changes to the grouping. Note that I *just* made a commit, so try the -dev version after midnight GMT to get the most current version. I'm pretty sure this will fix your problems.

#4

mongolito404 - November 5, 2009 - 13:21
Status:fixed» active

Switiching to 6.x-2.x-dev doesn't solve the issue.

Worse, now all fields are displayed empty. The sourrounding markup is here, but actual rendering of field values is missing. I check the "Hide empty fields" in style parameters, all the fields and their labels are still displayed.

#5

mongolito404 - November 5, 2009 - 13:54

Ok, it's not a bug, reverting the theme to Garland fix both issues. All I have to do is to debug my theme...

#6

mongolito404 - November 5, 2009 - 14:04
Status:active» won't fix

#7

mongolito404 - November 6, 2009 - 12:12
Category:support request» bug report
Status:won't fix» active

The the culprit is views-view-field.tpl.php in my theme folder... but even when the file is the same as the original sites/all/modules/views/theme/views-view-field.tpl.php, the grouping doesn't work in views-6.x-2.6 and all field disapear with views-6.x-2.7.

Finaly, it may be a bug.

#8

dyke it - November 7, 2009 - 02:10

i'm having the same problem grouping by content type in a block with HTML list, unformatted and grid. the table style is grouping fine.

i'm using the latest dev. i also tried switching my theme to garland which doesn't work.

#9

dyke it - November 7, 2009 - 09:00

i updated to the latest dev and it didn't appear to be working at first, but then i changed "distinct" to "no" and it worked (on all views styles). yay! :)

#10

mongolito404 - November 9, 2009 - 06:42

In my case, the "distinct" value is already "no". And switching theme works, do does removing views-view-field.tpl.php from my theme.

#11

tompte - November 9, 2009 - 10:28

I have the same problem.
Distinct or not...

#12

dyke it - November 9, 2009 - 11:26

i was wrong, it isn't grouping properly whether distinct or not. i'm also having the same problem with grouping in all views.

#13

trupal218 - November 10, 2009 - 08:25

subscribing

#14

merlinofchaos - November 10, 2009 - 21:21
Status:active» postponed (maintainer needs more info)

Does this patch fix it? http://drupal.org/node/619884#comment-2250378 -- I suspect not. If that patch doesn't fix it, it may be a problem with date.module itself, because the grouping is ultimately handled by the style and I suspect you're using a date.module provided style.

Please test that patch and if that patch doesn't fix it, reroute this issue to date.module

#15

mongolito404 - November 11, 2009 - 09:36

Ok, I will try the patch asap. But if it doesn't fix the issue, I doubt the bug is in the date.module. As I said, removing the views-view-field.tpl.php file from the theme folder solve the issue. Even if it's an identical copy of the the original sites/all/modules/views/theme/views-view-field.tpl.php one. Also, when updating Views to 6.x-2.7, the issue is worse as all fields are rendered as the empty string. Again, having no views-view-field.tpl.php in the theme folder solve the issue in 6.x-2.7.

#16

merlinofchaos - November 11, 2009 - 18:29
Status:postponed (maintainer needs more info)» won't fix

OH! If it's related to the presence of absence of that template, that's a core bug. =) I think it may be http://drupal.org/node/591804

 
 

Drupal is a registered trademark of Dries Buytaert.