public function ExtraResult::render in Views Extras (Session/Cookie/Token Support) 8
Same name and namespace in other branches
- 2.x src/Plugin/views/area/ExtraResult.php \Drupal\views_extras\Plugin\views\area\ExtraResult::render()
Render the area.
Parameters
bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.
Return value
array In any case we need a valid Drupal render array to return.
Overrides AreaPluginBase::render
File
- src/
Plugin/ views/ area/ ExtraResult.php, line 74
Class
- ExtraResult
- Views area handler to display some configurable result summary.
Namespace
Drupal\views_extras\Plugin\views\areaCode
public function render($empty = FALSE) {
// Must have options and does not work on summaries.
if (!isset($this->options['content']) || $this->view->style_plugin instanceof DefaultSummary) {
return array();
}
$output = '';
$format = $this->options['content'];
// Calculate the page totals.
$current_page = (int) $this->view
->getCurrentPage() + 1;
$per_page = (int) $this->view
->getItemsPerPage();
// @TODO: Maybe use a possible is views empty functionality.
// Not every view has total_rows set, use view->result instead.
$total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result);
$label = Html::escape($this->view->storage
->label());
if ($per_page === 0) {
$page_count = 1;
$start = 1;
$end = $total;
}
else {
$page_count = (int) ceil($total / $per_page);
$total_count = $current_page * $per_page;
if ($total_count > $total) {
$total_count = $total;
}
$start = ($current_page - 1) * $per_page + 1;
$end = $total_count;
}
$current_record_count = $end - $start + 1;
// Get the search information.
$replacements = [];
$replacements['@start'] = $start;
$replacements['@end'] = $end;
$replacements['@total'] = $total;
$replacements['@label'] = $label;
$replacements['@per_page'] = $per_page;
$replacements['@current_page'] = $current_page;
$replacements['@current_record_count'] = $current_record_count;
$replacements['@page_count'] = $page_count;
$replacements['@more'] = $total - $current_record_count;
// Send the output.
if (!empty($total)) {
$format_list = explode(PHP_EOL, $format);
foreach ($format_list as $value) {
if (strpos($value, '@more')) {
//condition to hide more count when its 0.
if ($replacements['@more'] > 0) {
$output .= Xss::filterAdmin(str_replace(array_keys($replacements), array_values($replacements), $value));
}
}
else {
$output .= Xss::filterAdmin(str_replace(array_keys($replacements), array_values($replacements), $value));
}
}
}
// Return as render array.
return array(
'#markup' => $output,
);
}