Empty search results gives error re mini pager
Description of the bug
When using the site search with the mini pager, I get errors if there are no results found.
Steps To Reproduce
To reproduce the behavior:
- Go to 'admin/config/search/settings'
- Enable mini pager for search results and save the config.
- Go to the site search page at 'search/node'
- In the search box, enter something that doesn't exist on the site, say 'arknvpanmezxq'
- Click 'Search'
Actual behavior
These errors appear, in addition to the expected message about no results found.
Warning: Trying to access array offset on value of type null in theme_views_mini_pager() (line 1146 of /var/www/backdrop1/core/modules/views/templates/views.theme.inc).
Warning: Trying to access array offset on value of type null in theme_views_mini_pager() (line 1148 of /var/www/backdrop1/core/modules/views/templates/views.theme.inc).
Warning: Trying to access array offset on value of type null in theme_views_mini_pager() (line 1151 of /var/www/backdrop1/core/modules/views/templates/views.theme.inc).
Expected behavior
Should not get those errors. :)
Additional information
Add any other information that could help, such as:
- Backdrop CMS version: 1.27.0
- Web server and its version: Apache/2.4.54
- PHP version: 8.1.15
- Database sever (MySQL or MariaDB?) and its version: 10.5.18-MariaDB
- Operating System and its version: Fedora 35
- Browser(s) and their versions: Brave 1.61.104
The code in question:
// Current is the page we are currently paged to.
$pager_current = $pager_page_array[$element] + 1; // line 1146
// Max is the maximum page number.
$pager_max = $pager_total[$element]; // 1148
// End of marker calculations.
if ($pager_total[$element] > 1) { // 1151
It appears that $pager_page_array and $pager_total are both NULL in this case.
This looks simple enough that I could do a PR for it....
The PR is ready to be reviewed/tested.
I tested the steps to reproduce on a fresh site and was able to recreate the problem exactly as described.
I tested again on the sandbox site and the problem did not occur. So, the fix works for me in terms of resolving the described problem.
RTBC
Thanks @leeksoup, @herbdool, @docwilmot, and @stpaultim for fixing this issue! I have merged https://github.com/backdrop/backdrop/pull/4684 into 1.x and 1.27.x. Great job!