Skip to content

Commit a97b352

Browse files
committed
fix: hide view, download and filter buttons when there are no records
When a storage contains no records at all, only the empty-state infobox is shown. The view, download and filter doc-header buttons had nothing to act on and were dead controls, so they are now skipped when fullRecordCount is 0. The count is memoized to avoid a second query. The guard uses fullRecordCount, not recordCount, so the buttons still show when records exist but a search returns no matches. Resolves #107
1 parent f674878 commit a97b352

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

Classes/Controller/AbstractBackendController.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ abstract class AbstractBackendController extends ActionController implements Bac
116116

117117
protected array $viewDropdownButtons = [];
118118

119+
protected ?int $fullRecordCount = null;
120+
119121
protected ConnectionPool $connectionPool;
120122

121123
protected IconFactory $iconFactory;
@@ -674,8 +676,12 @@ protected function isDirectPublishingAllowed(): bool
674676
*/
675677
protected function getFullRecordCount(): int
676678
{
679+
if ($this->fullRecordCount !== null) {
680+
return $this->fullRecordCount;
681+
}
682+
677683
if ($this->getRequestedPids() === []) {
678-
return 0;
684+
return $this->fullRecordCount = 0;
679685
}
680686

681687
$tableName = $this->getTableName();
@@ -691,7 +697,7 @@ protected function getFullRecordCount(): int
691697
->executeQuery()
692698
->fetchNumeric();
693699

694-
return $count ? $count[0] : 0;
700+
return $this->fullRecordCount = ($count ? $count[0] : 0);
695701
}
696702

697703
protected function getRequestedPids(): array
@@ -2182,6 +2188,11 @@ protected function addResetViewButtonToViewDropdown(): void
21822188

21832189
protected function addDownloadButtonToModuleTemplate(): void
21842190
{
2191+
// With no records at all the export would be empty; skip the button.
2192+
if ($this->getFullRecordCount() === 0) {
2193+
return;
2194+
}
2195+
21852196
if (!$this->isActionAllowedInCurrentTemplate('download')) {
21862197
return;
21872198
}
@@ -2238,6 +2249,11 @@ protected function getActiveFilterCount(): int
22382249

22392250
protected function addToggleFiltersButtonToNewModuleTemplate(): void
22402251
{
2252+
// With no records at all there is nothing to filter; skip the button.
2253+
if ($this->getFullRecordCount() === 0) {
2254+
return;
2255+
}
2256+
22412257
if (!$this->isActionAllowedInCurrentTemplate('toggleFilters')) {
22422258
return;
22432259
}
@@ -2498,6 +2514,11 @@ protected function assignViewVariables(): void
24982514

24992515
protected function addViewDropdownButtonToModuleTemplate(): void
25002516
{
2517+
// With no records at all there is no table to configure; skip the button.
2518+
if ($this->getFullRecordCount() === 0) {
2519+
return;
2520+
}
2521+
25012522
if (empty($this->viewDropdownButtons)) {
25022523
return;
25032524
}

0 commit comments

Comments
 (0)