Skip to content

Instantly share code, notes, and snippets.

@Seorusus
Created December 14, 2022 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seorusus/94023e2bfd36eebde67cebbf7c81bc98 to your computer and use it in GitHub Desktop.
Save Seorusus/94023e2bfd36eebde67cebbf7c81bc98 to your computer and use it in GitHub Desktop.
Счетчик количества айтемов в таблице
/**
* Implements hook_preprocess_views_view().
*/
function basf_views_preprocess_views_view(&$variables): void {
global $language;
$view = $variables['view'];
if ($view->id() === 'search' && $view->current_display === 'search_page') {
$query = $view->getExposedInput();
if (isset($query['query']) && $query['query']) {
$variables['search_input'] = t(
'Search results for “@query”',
['@query' => $query['query']]
);
}
else {
$variables['search_input'] = t('Search results');
}
$variables['totalRows'] = t('@totalRows hits', ['@totalRows' => $view->total_rows]);
$variables['bottom_content'] = _basf_views_get_bottom_card_grid();
}
if ($view->id() === 'listing_msds' && $view->current_display === 'msds') {
// TODO $country should be implemented.
$country = NULL;
$query = $view->query->query()->countQuery()->execute()->fetchAssoc();
$count = reset($query);
// Gets count of views table items.
if (empty($country)) {
$variables['count'] = t(
'@count hits in @language',
[
'@count' => $count,
'@language' => $language,
]
);
}
else {
$variables['count'] = t(
'@count hits for @country in @language',
[
'@count' => $count,
'@country' => $country,
'@language' => $language,
]
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment