Commit e39328a6 authored by catch's avatar catch

Issue #2508145 by jibran, s.reichert: Grouping level is always zero in Views

parent 2ded87b1
...@@ -482,9 +482,17 @@ public function render() { ...@@ -482,9 +482,17 @@ public function render() {
* grouping. * grouping.
* *
* @param $sets * @param $sets
* Array containing the grouping sets to render. * An array keyed by group content containing the grouping sets to render.
* Each set contains the following associative array:
* - group: The group content.
* - level: The hierarchical level of the grouping.
* - rows: The result rows to be rendered in this group..
* @param $level * @param $level
* Integer indicating the hierarchical level of the grouping. * (deprecated) This is no longer used and will be removed in Drupal 9. The
* 'level' key in $sets is used to indicate the hierarchical level of the
* grouping.
*
* @todo Remove the $level parameter in https://www.drupal.org/node/2633890.
* *
* @return string * @return string
* Rendered output of given grouping sets. * Rendered output of given grouping sets.
...@@ -493,16 +501,16 @@ public function renderGroupingSets($sets, $level = 0) { ...@@ -493,16 +501,16 @@ public function renderGroupingSets($sets, $level = 0) {
$output = array(); $output = array();
$theme_functions = $this->view->buildThemeFunctions($this->groupingTheme); $theme_functions = $this->view->buildThemeFunctions($this->groupingTheme);
foreach ($sets as $set) { foreach ($sets as $set) {
$level = isset($set['level']) ? $set['level'] : 0;
$row = reset($set['rows']); $row = reset($set['rows']);
// Render as a grouping set. // Render as a grouping set.
if (is_array($row) && isset($row['group'])) { if (is_array($row) && isset($row['group'])) {
$output[] = array( $single_output = array(
'#theme' => $theme_functions, '#theme' => $theme_functions,
'#view' => $this->view, '#view' => $this->view,
'#grouping' => $this->options['grouping'][$level], '#grouping' => $this->options['grouping'][$level],
'#grouping_level' => $level,
'#rows' => $set['rows'], '#rows' => $set['rows'],
'#title' => $set['group'],
); );
} }
// Render as a record set. // Render as a record set.
...@@ -515,10 +523,11 @@ public function renderGroupingSets($sets, $level = 0) { ...@@ -515,10 +523,11 @@ public function renderGroupingSets($sets, $level = 0) {
} }
$single_output = $this->renderRowGroup($set['rows']); $single_output = $this->renderRowGroup($set['rows']);
$single_output['#grouping_level'] = $level;
$single_output['#title'] = $set['group'];
$output[] = $single_output;
} }
$single_output['#grouping_level'] = $level;
$single_output['#title'] = $set['group'];
$output[] = $single_output;
} }
unset($this->view->row_index); unset($this->view->row_index);
return $output; return $output;
...@@ -546,9 +555,11 @@ public function renderGroupingSets($sets, $level = 0) { ...@@ -546,9 +555,11 @@ public function renderGroupingSets($sets, $level = 0) {
* array( * array(
* 'grouping_field_1:grouping_1' => array( * 'grouping_field_1:grouping_1' => array(
* 'group' => 'grouping_field_1:content_1', * 'group' => 'grouping_field_1:content_1',
* 'level' => 0,
* 'rows' => array( * 'rows' => array(
* 'grouping_field_2:grouping_a' => array( * 'grouping_field_2:grouping_a' => array(
* 'group' => 'grouping_field_2:content_a', * 'group' => 'grouping_field_2:content_a',
* 'level' => 1,
* 'rows' => array( * 'rows' => array(
* $row_index_1 => $row_1, * $row_index_1 => $row_1,
* $row_index_2 => $row_2, * $row_index_2 => $row_2,
...@@ -580,7 +591,7 @@ public function renderGrouping($records, $groupings = array(), $group_rendered = ...@@ -580,7 +591,7 @@ public function renderGrouping($records, $groupings = array(), $group_rendered =
// hierarchically positioned set where the current row belongs to. // hierarchically positioned set where the current row belongs to.
// While iterating, parent groups, that do not exist yet, are added. // While iterating, parent groups, that do not exist yet, are added.
$set = &$sets; $set = &$sets;
foreach ($groupings as $info) { foreach ($groupings as $level => $info) {
$field = $info['field']; $field = $info['field'];
$rendered = isset($info['rendered']) ? $info['rendered'] : $group_rendered; $rendered = isset($info['rendered']) ? $info['rendered'] : $group_rendered;
$rendered_strip = isset($info['rendered_strip']) ? $info['rendered_strip'] : FALSE; $rendered_strip = isset($info['rendered_strip']) ? $info['rendered_strip'] : FALSE;
...@@ -613,6 +624,7 @@ public function renderGrouping($records, $groupings = array(), $group_rendered = ...@@ -613,6 +624,7 @@ public function renderGrouping($records, $groupings = array(), $group_rendered =
// Create the group if it does not exist yet. // Create the group if it does not exist yet.
if (empty($set[$grouping])) { if (empty($set[$grouping])) {
$set[$grouping]['group'] = $group_content; $set[$grouping]['group'] = $group_content;
$set[$grouping]['level'] = $level;
$set[$grouping]['rows'] = array(); $set[$grouping]['rows'] = array();
} }
......
...@@ -149,8 +149,10 @@ function _testGrouping($stripped = FALSE) { ...@@ -149,8 +149,10 @@ function _testGrouping($stripped = FALSE) {
$expected = array(); $expected = array();
$expected['Job: Singer'] = array(); $expected['Job: Singer'] = array();
$expected['Job: Singer']['group'] = 'Job: Singer'; $expected['Job: Singer']['group'] = 'Job: Singer';
$expected['Job: Singer']['level'] = 0;
$expected['Job: Singer']['rows']['Age: 25'] = array(); $expected['Job: Singer']['rows']['Age: 25'] = array();
$expected['Job: Singer']['rows']['Age: 25']['group'] = 'Age: 25'; $expected['Job: Singer']['rows']['Age: 25']['group'] = 'Age: 25';
$expected['Job: Singer']['rows']['Age: 25']['level'] = 1;
$expected['Job: Singer']['rows']['Age: 25']['rows'][0] = new ResultRow(['index' => 0]); $expected['Job: Singer']['rows']['Age: 25']['rows'][0] = new ResultRow(['index' => 0]);
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_name = 'John'; $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_name = 'John';
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_job = 'Singer'; $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_job = 'Singer';
...@@ -158,6 +160,7 @@ function _testGrouping($stripped = FALSE) { ...@@ -158,6 +160,7 @@ function _testGrouping($stripped = FALSE) {
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_id = '1'; $expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_id = '1';
$expected['Job: Singer']['rows']['Age: 27'] = array(); $expected['Job: Singer']['rows']['Age: 27'] = array();
$expected['Job: Singer']['rows']['Age: 27']['group'] = 'Age: 27'; $expected['Job: Singer']['rows']['Age: 27']['group'] = 'Age: 27';
$expected['Job: Singer']['rows']['Age: 27']['level'] = 1;
$expected['Job: Singer']['rows']['Age: 27']['rows'][1] = new ResultRow(['index' => 1]); $expected['Job: Singer']['rows']['Age: 27']['rows'][1] = new ResultRow(['index' => 1]);
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_name = 'George'; $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_name = 'George';
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_job = 'Singer'; $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_job = 'Singer';
...@@ -165,8 +168,10 @@ function _testGrouping($stripped = FALSE) { ...@@ -165,8 +168,10 @@ function _testGrouping($stripped = FALSE) {
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_id = '2'; $expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_id = '2';
$expected['Job: Drummer'] = array(); $expected['Job: Drummer'] = array();
$expected['Job: Drummer']['group'] = 'Job: Drummer'; $expected['Job: Drummer']['group'] = 'Job: Drummer';
$expected['Job: Drummer']['level'] = 0;
$expected['Job: Drummer']['rows']['Age: 28'] = array(); $expected['Job: Drummer']['rows']['Age: 28'] = array();
$expected['Job: Drummer']['rows']['Age: 28']['group'] = 'Age: 28'; $expected['Job: Drummer']['rows']['Age: 28']['group'] = 'Age: 28';
$expected['Job: Drummer']['rows']['Age: 28']['level'] = 1;
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2] = new ResultRow(['index' => 2]); $expected['Job: Drummer']['rows']['Age: 28']['rows'][2] = new ResultRow(['index' => 2]);
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_name = 'Ringo'; $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_name = 'Ringo';
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_job = 'Drummer'; $expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_job = 'Drummer';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment