By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x-3.x
Issue links:
Description:
In order to override how a single view of a grouped view was rendered a style plugin
had to do hard work, just to, for example pass in an additional parameter to the theme function.
Before
class YourStylePlugin extends StylePluginBase {
/**
* Overrides \StylePluginBase::render_grouping_sets().
*/
protected function render_grouping_sets($sets, $level = 0) {
$output = array();
$theme_functions = views_theme_functions('views_view_grouping', $this->view, $this->view->display_handler->display);
foreach ($sets as $set) {
$row = reset($set['rows']);
// Render as a grouping set.
if (is_array($row) && isset($row['group'])) {
$output[] = array(
'#theme' => $theme_functions,
'#view' => $this->view,
'#grouping' => $this->options['grouping'][$level],
'#grouping_level' => $level,
'#rows' => $set['rows'],
'#title' => $set['group'],
);
}
// Render as a record set.
else {
if ($this->usesRowPlugin()) {
foreach ($set['rows'] as $index => $row) {
$this->view->row_index = $index;
$render = $this->view->rowPlugin->render($row);
// Row render arrays cannot be contained by style render arrays.
$set['rows'][$index] = drupal_render($render);
}
}
$output[] = array(
'#theme' => $this->themeFunctions(),
'#view' => $this->view,
'#options' => $this->options,
'#grouping_level' => $level,
'#rows' => $set['rows'],
'#title' => $set['group'],
//Additional parameter to my theme function.
'#additional_parameter' => 'foo',
);
}
}
unset($this->view->row_index);
return $output;
}
}
After
Now all you need is to override the renderSingleGroup():
class YourStylePlugin extends StylePluginBase {
/**
* Overrides \StylePluginBase::renderSingleGroup().
*/
protected function renderSingleGroup(array $rows = array()) {
return array(
'#theme' => $this->themeFunctions(),
'#view' => $this->view,
'#rows' => $rows,
//Additional parameter to my theme function.
'#additional_parameter' => 'foo',
);
}
}
Impacts:
Module developers