Skip to content

Commit

Permalink
LOYALIST-51 Contextual header results: template_preprocess_views_view
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmcd75 committed Jul 30, 2024
1 parent bc6f7bd commit 2084361
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,26 @@ function the_loyalist_collection_preprocess_input(&$variables) {
break;
}
}

/**
* Implements template_preprocess_views_view().
*/
function the_loyalist_collection_preprocess_views_view(&$vars) {
$view_header_result_markup = $vars['header']['result']['#markup'] ?? null;

if (!empty($view_header_result_markup)) {
// Override View|Header|Result summary|@total 'titles' re: single row result, if found.
$viewexecutable_total_rows_property = $vars['view']->total_rows ?? null;
if ($viewexecutable_total_rows_property == '1') {
$vars['header']['result']['#markup'] = str_replace('titles', 'title', $view_header_result_markup);
// Update markup variable re: further processing.
$view_header_result_markup = $vars['header']['result']['#markup'];
}
// Override/truncate View|Header|Result summary 'showing page etc.' text (if found) and getPagerTotal = 1.
$viewexecutable_getpagertotal = (int)$vars['view']->getPager()->getPagerTotal() ?? null;
if ($viewexecutable_getpagertotal == '1') {
$vars['header']['result']['#markup'] = preg_replace('/:\s*showing[^.]+/', '', $view_header_result_markup);
}
}

}

0 comments on commit 2084361

Please sign in to comment.