- Issue created by @cedewey
- π―π΄Jordan mohammad-fayoumi Amman
I'm facing the same exact issue, I'll try to identify the source of the bug
- π―π΄Jordan mohammad-fayoumi Amman
I've changed the pager ID to 2 in order to apply the condition in the following code:
function views_show_more_preprocess_views_show_more_pager(&$vars) { /** @var \Drupal\Core\Pager\PagerManagerInterface $pager_manager */ $pager_manager = \Drupal::service('pager.manager'); $element = $vars['element']; $parameters = $vars['parameters']; $pager = $pager_manager->getPager($element); if (!$pager) { return; } $current = $pager->getCurrentPage(); $total = $pager->getTotalPages(); $pager_classes = ['js-pager__items', 'pager__items', 'pager-show-more']; if ($current < ($total - 1)) { $options = [ 'query' => $pager_manager->getUpdatedParameters($parameters, $element, $current + 1), ]; $vars['item'] = [ 'href' => Url::fromRoute('<none>', [], $options), 'text' => $vars['options']['show_more_text'], 'attributes' => [ 'title' => t('Go to next page'), ], ]; } else { $pager_classes[] = 'pager-show-more-empty'; } $vars['attributes'] = new Attribute([ 'class' => $pager_classes, ]); // This is based on the entire current query string. We need to ensure // cacheability is affected accordingly. $vars['#cache']['contexts'][] = 'url.query_args'; $vars['heading_id'] = Html::getUniqueId('pagination-heading'); }
The reason I did this is because when printing the values of $current and ($total - 1), they would always display 0. By setting the pager ID to 2, I was able to ensure the condition works as expected.